From f291762ab3d83cdc872338b5014622ee3b7ab456 Mon Sep 17 00:00:00 2001 From: huangwei <983142558@qq.com> Date: Fri, 30 Aug 2024 23:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=9B=E6=B5=8B=E7=AC=AC=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=89=88=E6=9C=AC,=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 7 +- .../java/com/bingce/controlnetwork/App.java | 12 + .../fragmentcontainer/FragmentContainer.java | 3 +- .../SurveyorStationRecordsAdapter.java | 13 +- ...=> SurveyorStationRecordsWellAdapter.java} | 58 +- .../bean/SurveyorScheduleConstants.java | 88 ++ .../event/AutoSurveyorButtonVisibleEvent.java | 11 + .../event/RefreshRollBackEvent.java | 35 + .../event/ReplaceSurveyorFragmentEvent.java | 4 + .../event/SurveyStateEvent.java | 56 + .../ComponentSurveyorStationListFragment.java | 144 --- ...djustAloneVerOrDistanceDialogFragment.java | 128 ++ .../StationDataAdjustDialogFragment.java | 23 +- ...ava => StationSurveyorRecordFragment.java} | 110 +- .../stationsurvey/IMeasureOperate.java | 10 +- .../StationSettingCheckUtil.java | 213 ++++ .../StationSurveyorFragment.java | 315 +++-- .../MeasureDistanceFragment.java | 394 ------ .../angledistance/MeasureFragment.java | 180 --- .../stationsurvey/base/BaseFragmentLazy.java | 154 +++ .../base/MeasureBaseFragment.java | 2 +- .../MeasureHeightTraverseFragment.kt | 6 +- .../MeasureHeightTraverseSubFragment.java | 36 +- ...ationSurveyorSeparateDistanceFragment.java | 476 ++++++++ .../StationSurveyorSeparateFragment.java | 375 ++++++ ...ationSurveyorSeparateHorAngleFragment.java | 475 +++++++ ...ationSurveyorSeparateVerAngleFragment.java | 469 +++++++ .../StationSurveyorSepatateAdapter.java | 129 ++ ...ationSurveyorWellDistanceDataFragment.java | 500 ++++++++ .../well/StationSurveyorWellFragment.java | 457 +++++++ ...onSurveyorWellLevelAngleDataFragment.java} | 167 ++- .../controlnetwork/model/AloneAdjustItem.java | 186 +++ .../model/StationCheckErrorItem.java | 18 + .../model/StationCheckErrorPoint.java | 14 + .../newui/stationlist/StationListFragment.kt | 8 +- .../stationsetting/StationSettingsActivity.kt | 4 +- .../stationsurveyor/ISurveyorMenuOperate.java | 16 + .../StationSurveyorHomeActivity.kt | 162 +++ .../StationSurveyorHomeViewModel.kt | 28 + .../surveyor/data/CachedData.java | 1086 +++++++++++++++++ .../surveyor/data/CachedDataPointType.java | 8 + .../surveyor/data/FaultTolerantData.java | 16 + .../surveyor/data/ICachedData.java | 155 +++ .../surveyor/data/ICycleRecorder.java | 8 + .../data/IDistanceTypeChangeListener.java | 8 + .../data/IStationPointRecordCollect.java | 8 + .../surveyor/data/ISurveyorData.java | 83 ++ .../surveyor/data/SpeakCache.java | 39 + .../surveyor/data/SurveyorData.java | 245 ++++ .../surveyor/method/AutoSurveyorMethod.java | 276 +++++ .../surveyor/method/AverageValueMethod.java | 156 +++ .../method/DeviationValueOfRadianMethod.java | 577 +++++++++ .../surveyor/method/FindTargetMethod.java | 181 +++ .../method/SingleCycleCheckMethod.java | 147 +++ .../method/SingleCycleTipsMethod.java | 10 +- .../method/SurveyorAdjustMethodTj.java | 642 ++++++++++ .../surveyor/method/ValueOf2cMethod.java | 119 ++ .../surveyor/method/model/CacheResult.java | 11 + .../surveyor/method/model/IStateDelegate.java | 18 + .../surveyor/state/IAutoModeSwitcher.java | 27 + .../surveyor/state/ISurveyState.java | 13 + .../state/ISurveyorDataScrollDelegate.java | 10 + .../surveyor/state/StateConstantsTj.java | 54 + .../surveyor/state/StateManagerTj.java | 243 ++++ .../surveyor/state/StateType.java | 36 + .../surveyor/state/_Check2CState.java | 186 +++ .../_CheckHalfCycleZeroState.java | 37 +- .../surveyor/state/_CheckReadDataState.java | 163 +++ .../_CheckSingleCycleState.java | 33 +- .../surveyor/state/_CheckStationState.java | 411 +++++++ .../_CheckStationSuccessState.java | 13 +- .../surveyor/state/_DoAutoSurveyorState.java | 30 + .../surveyor/state/_DoCalAdjustState.java | 47 + .../_DoCalScheduleInAllCycleState.java | 35 +- .../_DoCalScheduleInSingleCycleState.java | 31 +- .../state/_DoDeleteAllCycleState.java | 51 + .../state/_DoDeleteCurrentCycleState.java | 53 + .../_DoMove2NextValidateState.java | 19 +- .../{angledistance => }/_DoMoveBackState.java | 61 +- .../surveyor/state/_DoRecordCleanState.java | 44 + .../{angledistance => }/_DoSurveyorState.java | 187 +-- .../_DoWellMeasureRotationReadyState.java | 34 + .../surveyor/state/_IdleState.java | 251 ++++ .../_Is2CCheckReadyState.java | 15 +- .../_IsAllCycleCompletedState.java | 41 +- .../_IsHalfCycleZeroCheckReadyState.java | 16 +- .../_IsSingleCycleCompletedState.java | 19 +- .../_SurveyorFailureState.java | 12 +- .../surveyor/state/__BaseState.java | 306 +++++ .../StateManagerAloneDistance.java | 498 -------- .../alonedistance/_CheckReadDataState.java | 75 -- .../alonedistance/_CheckSingleCycleState.java | 90 -- .../alonedistance/_CheckStationState.java | 195 --- .../_CheckStationSuccessState.java | 33 - .../alonedistance/_DoAutoSurveyorState.java | 32 - .../alonedistance/_DoCalAdjustState.java | 74 -- .../_DoCalScheduleInSingleCycleState.java | 108 -- .../alonedistance/_DoDeleteAllCycleState.java | 63 - .../_DoDeleteCurrentCycleState.java | 55 - .../_DoMove2NextValidateState.java | 72 -- .../state/alonedistance/_DoMoveBackState.java | 85 -- .../state/alonedistance/_DoSurveyorState.java | 181 --- .../_DoWellMeasureRotationReadyState.java | 41 - .../state/alonedistance/_IdleState.java | 64 - .../_IsAllCycleCompletedState.java | 54 - .../_IsSingleCycleCompletedState.java | 61 - .../alonedistance/_SurveyorFailureState.java | 36 - .../state/alonedistance/__BaseState.java | 395 ------ .../state/angledistance/StateManager.java | 539 -------- .../state/angledistance/_Check2CState.java | 113 -- .../angledistance/_CheckReadDataState.java | 126 -- .../angledistance/_CheckStationState.java | 173 --- .../angledistance/_DoAutoSurveyorState.java | 32 - .../angledistance/_DoCalAdjustState.java | 44 - .../angledistance/_DoDeleteAllCycleState.java | 70 -- .../_DoDeleteCurrentCycleState.java | 69 -- .../angledistance/_DoRecordCleanState.java | 32 - .../_DoWellMeasureRotationReadyState.java | 30 - .../state/angledistance/_IdleState.java | 134 -- .../state/angledistance/__BaseState.java | 586 --------- .../surveyor/state/base/AbstructState.java | 349 ++++++ .../state/base/AbstructStateManager.java | 381 ++++++ .../state/base/AdjustmentMeasureWhatUtil.java | 25 + .../base/CallBackDeleteLearnBaseData.java | 5 + .../state/base/CheckToleranceUtil.java | 51 + .../StateManagerHeightTraverse.java | 2 +- .../heighttraverse/_DoSurveyorState.java | 1 + .../StateManagerSeparateVerAngle.java | 259 ++++ .../separateVerAngle/VerAngleCheckReadUtil.kt | 26 + .../VerAngleCheckTolerance.kt | 419 +++++++ .../separateVerAngle/VerAngleFindIndexUtil.kt | 123 ++ .../separateVerAngle/VerDeleteDataUtil.kt | 24 + .../_DoAutoSurveyorState.java | 33 + .../separateVerAngle/_DoSurveyorStateVer.java | 211 ++++ .../state/separateVerAngle/_IdleStateVer.java | 134 ++ .../_SurveyorFailureStateVer.java} | 18 +- .../separateVerAngle/__BaseStateVer.java | 419 +++++++ .../IWeatherShowDialogListener.kt | 11 + .../state/wellDistance/StateManagerWell.java | 270 ++++ .../wellDistance/SurveyorWellConstant.kt | 5 + .../WellDistanceFindIndexUtil.java | 37 + .../wellDistance/_CheckToleranceState.java | 172 +++ .../state/wellDistance/_DoSurveyorState.java | 207 ++++ .../state/wellDistance/_IdleState.java | 50 + .../state/wellDistance/__BaseState.java | 561 +++++++++ .../surveyor/surveyor/IAutoSurveyor.java | 27 + .../surveyor/surveyor/ISurveyor.java | 22 + .../surveyor/surveyor/ISurveyorListener.java | 7 + .../surveyor/ISurveyorRemindListener.java | 5 + .../surveyor/surveyor/RequestParam.java | 77 ++ .../surveyor/surveyor/SurveyorAutoImpl.java | 202 +++ .../surveyor/surveyor/SurveyorMock.java | 176 +++ .../surveyor/surveyor/SurveyorMockAuto.java | 268 ++++ .../surveyor/surveyor/SurveyorSingleImpl.java | 258 ++++ .../surveyor/TestDataSelectFragment.java | 13 +- .../surveyor/TestDataSelectLevelFragment.java | 136 +++ .../surveyor/surveyor/TestTj.java | 180 +++ .../ui/vh/AbstractSurveyorDataViewHolder.java | 107 ++ .../StationAdjustAloneDistanceViewHolder.java | 21 + .../SurveyorDataAloneDistanceViewHolder.java | 15 +- .../ui/vh/SurveyorDataViewHolder.java | 237 ++-- .../SurveyorDataWellDistanceViewHolder.java | 254 ++++ .../bingce/controlnetwork/util/IdUtil.java | 10 + .../controlnetwork/util/StationUtilPla.java | 121 ++ .../util/SupportAutoSurveyorUtil.kt | 26 + ...ct_surveyor_station_detail_layout_well.xml | 79 ++ ...tion_data_adjust_dialog_alone_distance.xml | 66 + .../fragment_station_surveyor_separate.xml | 47 + ...nt_station_surveyor_separate_hor_angle.xml | 45 + ...nt_station_surveyor_separate_ver_angle.xml | 46 + .../item_station_adjust_alone_distance.xml | 36 + .../new_activity_station_surveyor_home.xml | 5 + ...yor_station_record_data_edit_debug_pla.xml | 16 +- ...r_station_record_data_edit_release_pla.xml | 12 +- app/src/main/res/values-zh/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 176 files changed, 16513 insertions(+), 5715 deletions(-) rename app/src/main/java/com/bingce/controlnetwork/adapter/{MeasureAngleDistanceAdapter.java => SurveyorStationRecordsWellAdapter.java} (65%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/bean/SurveyorScheduleConstants.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/event/AutoSurveyorButtonVisibleEvent.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/event/RefreshRollBackEvent.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/event/ReplaceSurveyorFragmentEvent.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/event/SurveyStateEvent.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/ComponentSurveyorStationListFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustAloneVerOrDistanceDialogFragment.java rename app/src/main/java/com/bingce/controlnetwork/fragment/{ComponentStationSurveyorDataListFragment.java => StationSurveyorRecordFragment.java} (73%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSettingCheckUtil.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDistanceFragment.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/BaseFragmentLazy.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateDistanceFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateHorAngleFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateVerAngleFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSepatateAdapter.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellDistanceDataFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellFragment.java rename app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/{angledistance/MeasureDefaultFragment.java => well/StationSurveyorWellLevelAngleDataFragment.java} (70%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/model/AloneAdjustItem.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorItem.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorPoint.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsurveyor/ISurveyorMenuOperate.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsurveyor/StationSurveyorHomeActivity.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsurveyor/StationSurveyorHomeViewModel.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedData.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedDataPointType.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/FaultTolerantData.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICachedData.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICycleRecorder.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/IDistanceTypeChangeListener.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/IStationPointRecordCollect.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/ISurveyorData.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/SpeakCache.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/data/SurveyorData.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/AutoSurveyorMethod.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/AverageValueMethod.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/DeviationValueOfRadianMethod.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/FindTargetMethod.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleCheckMethod.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/SurveyorAdjustMethodTj.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/ValueOf2cMethod.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/CacheResult.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/IStateDelegate.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/IAutoModeSwitcher.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyorDataScrollDelegate.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateConstantsTj.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateManagerTj.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateType.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Check2CState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_CheckHalfCycleZeroState.java (74%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckReadDataState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_CheckSingleCycleState.java (73%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_CheckStationSuccessState.java (67%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoAutoSurveyorState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalAdjustState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_DoCalScheduleInAllCycleState.java (77%) rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_DoCalScheduleInSingleCycleState.java (73%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteAllCycleState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteCurrentCycleState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_DoMove2NextValidateState.java (81%) rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_DoMoveBackState.java (72%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoRecordCleanState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_DoSurveyorState.java (68%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoWellMeasureRotationReadyState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IdleState.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_Is2CCheckReadyState.java (75%) rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_IsAllCycleCompletedState.java (51%) rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_IsHalfCycleZeroCheckReadyState.java (81%) rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_IsSingleCycleCompletedState.java (72%) rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{angledistance => }/_SurveyorFailureState.java (71%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/__BaseState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/StateManagerAloneDistance.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckReadDataState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckSingleCycleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationSuccessState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoAutoSurveyorState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalAdjustState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalScheduleInSingleCycleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteAllCycleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteCurrentCycleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMove2NextValidateState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMoveBackState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoSurveyorState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoWellMeasureRotationReadyState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IdleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsAllCycleCompletedState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsSingleCycleCompletedState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_SurveyorFailureState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/__BaseState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/StateManager.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Check2CState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckReadDataState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoAutoSurveyorState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalAdjustState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteAllCycleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteCurrentCycleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoRecordCleanState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoWellMeasureRotationReadyState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IdleState.java delete mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/__BaseState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructStateManager.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AdjustmentMeasureWhatUtil.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CallBackDeleteLearnBaseData.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CheckToleranceUtil.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/StateManagerSeparateVerAngle.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckReadUtil.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckTolerance.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleFindIndexUtil.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerDeleteDataUtil.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoAutoSurveyorState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoSurveyorStateVer.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_IdleStateVer.java rename app/src/main/java/com/bingce/controlnetwork/surveyor/state/{heighttraverse/_SurveyorFailureState.java => separateVerAngle/_SurveyorFailureStateVer.java} (61%) create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/__BaseStateVer.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/IWeatherShowDialogListener.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/StateManagerWell.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/SurveyorWellConstant.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/WellDistanceFindIndexUtil.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_CheckToleranceState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_DoSurveyorState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_IdleState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/__BaseState.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/IAutoSurveyor.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyor.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorListener.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorRemindListener.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/RequestParam.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorAutoImpl.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMock.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMockAuto.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorSingleImpl.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectLevelFragment.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestTj.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/ui/vh/AbstractSurveyorDataViewHolder.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/ui/vh/StationAdjustAloneDistanceViewHolder.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataWellDistanceViewHolder.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/util/IdUtil.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/util/StationUtilPla.java create mode 100644 app/src/main/java/com/bingce/controlnetwork/util/SupportAutoSurveyorUtil.kt create mode 100644 app/src/main/res/layout/fragment_project_surveyor_station_detail_layout_well.xml create mode 100644 app/src/main/res/layout/fragment_station_data_adjust_dialog_alone_distance.xml create mode 100644 app/src/main/res/layout/fragment_station_surveyor_separate.xml create mode 100644 app/src/main/res/layout/fragment_station_surveyor_separate_hor_angle.xml create mode 100644 app/src/main/res/layout/fragment_station_surveyor_separate_ver_angle.xml create mode 100644 app/src/main/res/layout/item_station_adjust_alone_distance.xml create mode 100644 app/src/main/res/layout/new_activity_station_surveyor_home.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9228c83..69c0c24 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -132,10 +132,10 @@ android:exported="true" android:label="数据备份" /> + android:exported="true" + android:label="数据导入" /> + \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/App.java b/app/src/main/java/com/bingce/controlnetwork/App.java index 1189ca5..d2c23b2 100644 --- a/app/src/main/java/com/bingce/controlnetwork/App.java +++ b/app/src/main/java/com/bingce/controlnetwork/App.java @@ -80,6 +80,18 @@ public class App extends RepositoryBaseApp { public String levelSurveyorTime; + public boolean isCompletedLearn; + + /** + * 自动测量是否二次照准 + */ + public boolean isTwiceAiming = true; + + /** + * 小数点位数 + */ + public int notNumber = 3; + private static App app; @Override diff --git a/app/src/main/java/com/bingce/controlnetwork/activity/fragmentcontainer/FragmentContainer.java b/app/src/main/java/com/bingce/controlnetwork/activity/fragmentcontainer/FragmentContainer.java index c118304..4bcf81a 100644 --- a/app/src/main/java/com/bingce/controlnetwork/activity/fragmentcontainer/FragmentContainer.java +++ b/app/src/main/java/com/bingce/controlnetwork/activity/fragmentcontainer/FragmentContainer.java @@ -30,7 +30,6 @@ import com.bingce.controlnetwork.fragment.stationdetail.SingleStationDetailAndEd import com.bingce.controlnetwork.fragment.stationsetting.StationSettingHeightTraverseFragment; import com.bingce.controlnetwork.fragment.stationsetting.StationSettingsFragment; import com.bingce.controlnetwork.fragment.stationsurvey.StationSurveyorFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment; import com.bingce.controlnetwork.fragment.stationsurvey.heighttraverse.MeasureHeightTraverseFragment; import com.bingce.controlnetwork.func.level.fragment.LevelRouteCreateEditFragment; import com.bingce.controlnetwork.func.level.fragment.LevelSelectExportFragment; @@ -71,7 +70,7 @@ public class FragmentContainer { factory.put(LineStationWellDoubleGroundSetupFragment.TAG, LineStationWellDoubleGroundSetupFragment::newInstance); factory.put(LineStationWellDoubleUnderGroundSetupFragment.TAG, LineStationWellDoubleUnderGroundSetupFragment::newInstance); factory.put(PrismManageFragment.TAG, PrismManageFragment::newInstance); - factory.put(MeasureFragment.TAG, MeasureFragment::newInstance); +// factory.put(MeasureFragment.TAG, MeasureFragment::newInstance); factory.put(CreateStationForHeightTraverseFragment.TAG, CreateStationForHeightTraverseFragment::newInstance); factory.put(MeasureHeightTraverseFragment.TAG, MeasureHeightTraverseFragment::newInstance); factory.put(SelectExportHeightTraverseFragment.TAG, SelectExportHeightTraverseFragment::newInstance); diff --git a/app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsAdapter.java b/app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsAdapter.java index 61ff774..c77501b 100644 --- a/app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsAdapter.java +++ b/app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsAdapter.java @@ -7,16 +7,15 @@ import androidx.recyclerview.widget.RecyclerView; import com.bingce.controlapphelper.model.IAdapter; import com.bingce.controlapphelper.model.ViewItemType; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.IDistanceTypeChangeListener; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; - -import org.jetbrains.annotations.NotNull; - +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; import com.bingce.controlnetwork.ui.vh.SurveyorDataViewHolder; import com.bingce.controlnetwork.ui.widget.ViewFactory; +import org.jetbrains.annotations.NotNull; + /* * 测量记录adapter * */ diff --git a/app/src/main/java/com/bingce/controlnetwork/adapter/MeasureAngleDistanceAdapter.java b/app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsWellAdapter.java similarity index 65% rename from app/src/main/java/com/bingce/controlnetwork/adapter/MeasureAngleDistanceAdapter.java rename to app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsWellAdapter.java index fd11fbb..3aa4499 100644 --- a/app/src/main/java/com/bingce/controlnetwork/adapter/MeasureAngleDistanceAdapter.java +++ b/app/src/main/java/com/bingce/controlnetwork/adapter/SurveyorStationRecordsWellAdapter.java @@ -7,41 +7,42 @@ import androidx.recyclerview.widget.RecyclerView; import com.bingce.controlapphelper.model.IAdapter; import com.bingce.controlapphelper.model.ViewItemType; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.IDistanceTypeChangeListener; -import com.bingce.controlapphelper.surveyor.data.IMeasureCache; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; - -import com.bingce.controlnetwork.ui.vh.SurveyorDataAloneDistanceViewHolder; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; import com.bingce.controlnetwork.ui.vh.SurveyorDataViewHolder; +import com.bingce.controlnetwork.ui.vh.SurveyorDataWellDistanceViewHolder; import com.bingce.controlnetwork.ui.widget.ViewFactory; + /** * 测量记录adapter * 井定向-距离 */ -public class MeasureAngleDistanceAdapter extends RecyclerView.Adapter +public class SurveyorStationRecordsWellAdapter extends RecyclerView.Adapter implements IAdapter, IDistanceTypeChangeListener { - public static final String TYPE_ANGLE = "TYPE_ANGLE"; + public static final String TYPE_HORIZONTAL_ANGLE = "TYPE_HORIZONTAL_ANGLE"; public static final String TYPE_DISTANCE = "TYPE_DISTANCE"; - private final IMeasureCache cachedData; + private ICachedData cachedData; private final ISurveyorData surveyorData; private final ICycleRecorder cycleRecorder; private boolean showSlopDistance = true; + private String projectType; private final String stationId; private final String type;//区分水平还是距离 - public MeasureAngleDistanceAdapter( + public SurveyorStationRecordsWellAdapter( + String projectType, String stationId, - IMeasureCache cachedData, + ICachedData cachedData, ICycleRecorder cycleRecorder, ISurveyorData surveyorData, String type) { + this.projectType = projectType; this.stationId = stationId; this.cachedData = cachedData; this.surveyorData = surveyorData; @@ -51,12 +52,19 @@ public class MeasureAngleDistanceAdapter extends RecyclerView.Adapter> stationLiveData; - - /** - * 去测量或者详情页面 - */ - private void goStationMeasureOrDetail(SurveyorStationRecord item, boolean detailOrSurveyorFinal) { - String stationId = item.getId(); - ThreadPoolUtil.execute(() -> { - SurveyorStationRecord stationRecord = SurveyorDatabaseFactory - .instance - .getSurveyorStation() - .getRecordSync(stationId); - if (stationRecord == null || stationRecord.getItems() == null || stationRecord.getItems().isEmpty()) { - return; - } - - String lineTypeFromStation = StationUtil.getLineTypeFromStation(stationRecord); - - //站的名称 导线+点名 - String stationName = StationUtil.getStationName(stationRecord); - - if (detailOrSurveyorFinal) { - SingleStationDetailAndEditFragment.start(getContext(), stationId, stationName, item.getProjectId(), null); - } else { - //StationSurveyorFragment原始测量页 - if (ProjectType.isConnection(item.projectType)) { - MeasureFragment.start(getContext(), stationId, stationName); - } else { - StationSurveyorFragment.start(getContext(), stationId, stationName); - } - } - }); - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_list_layout, container, false); - if (view instanceof RecyclerView) { - recyclerView = (RecyclerView) view; - if (getArguments() != null) { - update(getArguments().getString(BundleConstants.KEY_PROJECT_ID), - getArguments().getString(KEY_TIME_INDEX)); - } - } - return view; - } - - /** - * 根据项目id和测期id获取测站记录 - * - * @param projectId - * @param periodId - */ - public void update(String projectId, String periodId) { - if (stationLiveData != null) { - stationLiveData.removeObservers(this); - } - - stationLiveData = SurveyorDatabaseFactory - .instance - .getSurveyorStation().getLiveDataList(projectId, periodId); - - stationLiveData.observe(getViewLifecycleOwner(), this::updateUi); - } - - private void updateUi(List dataList) { - runOnUI(() -> { - if (adapter == null) { - boolean detailOrSurveyor = false; - if (getArguments() != null) { - detailOrSurveyor = getArguments().getBoolean(KEY_DETAIL_OR_SURVEYOR, false); - } - boolean detailOrSurveyorFinal = detailOrSurveyor; - adapter = new SurveyorStationListAdapter(dataList, - getChildFragmentManager(), - getViewLifecycleOwner(), - runnable -> { - if (getActivity() != null) { - getActivity().runOnUiThread(runnable); - } - }, - getContext(), - item -> goStationMeasureOrDetail(item, detailOrSurveyorFinal), - detailOrSurveyor); - recyclerView.setAdapter(adapter); - } else { - adapter.updateData(dataList); - } - }); - } - - private static final String KEY_TIME_INDEX = "___time_index__"; - private static final String KEY_DETAIL_OR_SURVEYOR = "___editable___";//标识点击item进入测量界面还是测站详情 - - public static ComponentSurveyorStationListFragment newInstance(String projectId, String surveyorPeriodId, boolean isDetail) { - ComponentSurveyorStationListFragment fragment = new ComponentSurveyorStationListFragment(); - Bundle bundle = new Bundle(); - bundle.putString(BundleConstants.KEY_PROJECT_ID, projectId); - bundle.putString(KEY_TIME_INDEX, surveyorPeriodId); - bundle.putBoolean(KEY_DETAIL_OR_SURVEYOR, isDetail); - fragment.setArguments(bundle); - return fragment; - } - - public static ComponentSurveyorStationListFragment newInstance(String projectId, String surveyorPeriodId) { - return newInstance(projectId, surveyorPeriodId, true); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustAloneVerOrDistanceDialogFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustAloneVerOrDistanceDialogFragment.java new file mode 100644 index 0000000..0b897e9 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustAloneVerOrDistanceDialogFragment.java @@ -0,0 +1,128 @@ +package com.bingce.controlnetwork.fragment; + +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.os.Parcelable; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.TextView; + +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.surveyor.method.ExportUtils; +import com.bingce.controlapphelper.surveyor.method.RadianMethod; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.adapter.BaseAdapter; +import com.bingce.controlnetwork.model.AloneAdjustItem; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.ui.vh.StationAdjustAloneDistanceViewHolder; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + + +public class StationDataAdjustAloneVerOrDistanceDialogFragment extends DialogFragment { + private static final String KEY_LIST = "__key_list"; + private static final String KEY_MEASURE_WHAT = "KEY_MEASURE_WHAT"; + private int measureWhatAloneAngleOrDistance; + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + if (getDialog() == null) { + return; + } + Window window = getDialog().getWindow(); + window.setBackgroundDrawable(new ColorDrawable(0x00000000)); + window.setLayout( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.WRAP_CONTENT); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_station_data_adjust_dialog_alone_distance, container, false); + if (getArguments() != null) { + measureWhatAloneAngleOrDistance = getArguments().getInt(KEY_MEASURE_WHAT); + ArrayList items = getArguments().getParcelableArrayList(KEY_LIST); + TextView tvTitle = rootView.findViewById(R.id.distance_angle_title); + tvTitle.setText(getTitle()); + RecyclerView recyclerView = rootView.findViewById(R.id.list); + _Adapter adapter = new _Adapter(items); + recyclerView.setAdapter(adapter); + } + return rootView; + } + + private String getTitle() { + if (StateConstantsTj.isMeasureVerAngle(measureWhatAloneAngleOrDistance)) { + return "垂直角"; + } else if (StateConstantsTj.isMeasureDistance(measureWhatAloneAngleOrDistance)) { + return "距离"; + } + return ""; + } + + + private class _Adapter extends BaseAdapter { + + public _Adapter(List items) { + super(items); + } + + @Override + protected StationAdjustAloneDistanceViewHolder createVH(@NotNull ViewGroup parent, int viewType) { + return new StationAdjustAloneDistanceViewHolder(getLayoutInflater().inflate(R.layout.item_station_adjust_alone_distance, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull @NotNull StationAdjustAloneDistanceViewHolder holder, int position) { + AloneAdjustItem item = getItem(position); + setText(holder.pointName, item.getPointName(), R.color.text_color_1); + + if (!TextUtils.isEmpty(item.getErrorMsg())) { + setText(holder.distance, item.getErrorMsg(), R.color.value_dirty); + } else { + setText(holder.distance, getShowText(item), R.color.text_color_1); + } + } + + private void setText(TextView textView, String string, @ColorRes int color) { + if (textView != null) { + textView.setText(string); + textView.setTextColor(Tools.getColor(color)); + } + } + + private String getShowText(AloneAdjustItem item) { + if (StateConstantsTj.isMeasureVerAngle(measureWhatAloneAngleOrDistance)) { + return RadianMethod.dmsStringOf(item.getVerAngle()); + } else if (StateConstantsTj.isMeasureDistance(measureWhatAloneAngleOrDistance)) { + return ExportUtils.formatDistance(item.getDistance()); + } + return ""; + } + + } + + public static void showDialog(FragmentManager fragmentManager, int measureWhat, List finalItemList) { + StationDataAdjustAloneVerOrDistanceDialogFragment dialogFragment = new StationDataAdjustAloneVerOrDistanceDialogFragment(); + Bundle args = new Bundle(); + args.putParcelableArrayList(KEY_LIST, (ArrayList) finalItemList); + args.putInt(KEY_MEASURE_WHAT, measureWhat); + dialogFragment.setArguments(args); + dialogFragment.show(fragmentManager, null); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustDialogFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustDialogFragment.java index 24fced5..c3e5b43 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustDialogFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/StationDataAdjustDialogFragment.java @@ -1,5 +1,6 @@ package com.bingce.controlnetwork.fragment; + import android.content.Context; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; @@ -20,7 +21,11 @@ import com.bingce.controlapphelper.model.ViewItemType; import com.bingce.controlapphelper.surveyor.method.RadianMethod; import com.bingce.controlapphelper.surveyor.method.SurveyorAdjustMethod; import com.bingce.controlapphelper.util.SettingValueUtil; +import com.bingce.controlnetwork.R; import com.bingce.controlnetwork.adapter.BaseAdapter; +import com.bingce.controlnetwork.surveyor.method.SurveyorAdjustMethodTj; +import com.bingce.controlnetwork.ui.vh.StationAdjustItemViewHolder; +import com.bingce.controlnetwork.ui.widget.ViewFactory; import com.bingce.utils.Util; import org.jetbrains.annotations.NotNull; @@ -28,11 +33,9 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.ui.vh.StationAdjustItemViewHolder; -import com.bingce.controlnetwork.ui.widget.ViewFactory; - public class StationDataAdjustDialogFragment extends DialogFragment { + public static final String KEY_MEASURE_WHAT = "__key_measure_what"; + public static final String KEY_SHOW_TYPE = "__key_show_type"; private static final String KEY_LIST = "__key_list"; private static final String KEY_IS_SHOW_SLOP_DISTANCE = "__key_show_slop"; @@ -180,4 +183,16 @@ public class StationDataAdjustDialogFragment extends DialogFragment { dialogFragment.setArguments(args); dialogFragment.show(fragmentManager, StationDataAdjustDialogFragment.class.getName()); } + + public static void showDialog(int measureWhat, ArrayList finalItemList, + Boolean isShowSlopDistance, + FragmentManager fragmentManager) { + StationDataAdjustDialogFragment dialogFragment = new StationDataAdjustDialogFragment(); + Bundle args = new Bundle(); + args.putInt(KEY_MEASURE_WHAT, measureWhat); + args.putParcelableArrayList(KEY_LIST, finalItemList); + args.putBoolean(KEY_IS_SHOW_SLOP_DISTANCE, isShowSlopDistance); + dialogFragment.setArguments(args); + dialogFragment.show(fragmentManager, StationDataAdjustDialogFragment.class.getName()); + } } diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/ComponentStationSurveyorDataListFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/StationSurveyorRecordFragment.java similarity index 73% rename from app/src/main/java/com/bingce/controlnetwork/fragment/ComponentStationSurveyorDataListFragment.java rename to app/src/main/java/com/bingce/controlnetwork/fragment/StationSurveyorRecordFragment.java index 9c897d9..568cb93 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/ComponentStationSurveyorDataListFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/StationSurveyorRecordFragment.java @@ -2,7 +2,6 @@ package com.bingce.controlnetwork.fragment; import android.content.Context; import android.os.Bundle; -import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -16,40 +15,40 @@ import androidx.recyclerview.widget.RecyclerView; import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.surveyor.data.CachedData; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.IDistanceTypeChangeListener; -import com.bingce.controlapphelper.surveyor.data.SurveyorData; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParamAuto; import com.bingce.controlapphelper.util.DigitalUtil; import com.bingce.controlapphelper.util.IUIRunner; import com.bingce.controlnetwork.R; import com.bingce.controlnetwork.adapter.SurveyorStationRecordsAdapter; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; import com.bingce.controlnetwork.fragment.base.BaseFragment; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.controlnetwork.surveyor.state.angledistance.StateManager; -import com.bingce.totalstation.TotalStation; +import com.bingce.controlnetwork.surveyor.data.CachedData; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.SurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateManagerTj; import com.bingce.utils.ThreadPoolUtil; -import blankj.utilcode.util.ToastUtils; /** - * 测站某个测期的测量数据列表 + * 测量记录 */ -public class ComponentStationSurveyorDataListFragment extends BaseFragment +public class StationSurveyorRecordFragment extends BaseFragment implements IDistanceTypeChangeListener, ISurveyState { private SurveyorStationRecordsAdapter adapter = null; - private StateManager stateManager; + private StateManagerTj stateManager; private RecyclerView recyclerView; private IDistanceTypeChangeListener cachedDataListener = null; private IDistanceTypeChangeListener surveyedDataListener = null; private ISurveyState surveyState; + private String stationId() { if (getArguments() == null) { return null; @@ -75,7 +74,7 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment getChildFragmentManager(), getViewLifecycleOwner(), this::runOnUI, - index -> { + (cycleIndex, index) -> { if (index >= 0 && adapter != null && index < adapter.getItemCount()) { recyclerView.scrollToPosition(index); } @@ -83,6 +82,7 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment new ICollectCacheCallback() { @Override public void onFailure() { + //TODO 收集测站测量信息失败,提示 } @Override @@ -90,7 +90,7 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, - StateManager stateManager) { + StateManagerTj stateManager) { onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); surveyState = stateManager; } @@ -105,13 +105,16 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, - StateManager stateManager) { + StateManagerTj stateManager) { this.stateManager = stateManager; cachedDataListener = cachedData; surveyedDataListener = surveyorData; //测量数据收集完毕后,就可以更新UI了 runOnUI(() -> { + if (getView() == null) { + return; + } //刷新UI if (adapter == null) { adapter = new SurveyorStationRecordsAdapter(stationId(), cachedData, surveyorData, surveyorData); @@ -126,14 +129,14 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment } } -// //监听测站数据 -// //监听「平距」「斜距」切换,更新UI显示 -// SurveyorDatabaseFactory -// .instance -// .getSurveyorStation() -// .getLiveDataRecord(stationId()) -// .observe(getViewLifecycleOwner(), -// surveyorStationRecord -> onShowSlopDistance(surveyorStationRecord.isShowSlopDistance())); + //监听测站数据 + //监听「平距」「斜距」切换,更新UI显示 + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getLiveDataRecord(stationId()) + .observe(getViewLifecycleOwner(), + surveyorStationRecord -> onShowSlopDistance(surveyorStationRecord.isShowSlopDistance())); }); } @@ -146,21 +149,23 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment FragmentManager fragmentManager, LifecycleOwner lifecycleOwner, IUIRunner runner, - IScrollDelegate scrollDelegate, + ISurveyorDataScrollDelegate scrollDelegate, ICollectCacheCallback callback) { if (callback == null) { return; } - boolean isSupportAutoMode = TotalStation.getInstance().isSupportMotor(); ThreadPoolUtil.execute(() -> { + + int measureWhat = StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT; + //读取当前测站的当前测回--很重要 SurveyorScheduleRecord scheduleRecord = SurveyorDatabaseFactory .instance .getScheduleDataSource() - .findScheduleSync(SurveyorScheduleConstants.getCurrentCycleKey(stationId, null)); + .findScheduleSync(SurveyorScheduleConstants.stationCurrentCycleKey(stationId, measureWhat)); int defaultCycle = scheduleRecord == null ? 0 : - DigitalUtil.valueOfIntString(scheduleRecord.getStatue(), 0); + DigitalUtil.string2Int(scheduleRecord.getStatue(), 0); //加载测站信息 SurveyorStationRecord surveyorStationRecord = SurveyorDatabaseFactory @@ -187,7 +192,7 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment } //创建缓存数据 CachedData cachedData = - CachedData.newInstance(surveyorStationRecord.isAutoClose(), + CachedData.newInstance(measureWhat, CachedDataPointType.ALL_POINT, surveyorStationRecord.isAutoClose(), surveyorStationRecord.isLeftAndRightSurveyor(), stationId, toleranceRecord); if (cachedData == null) { @@ -203,16 +208,13 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment //创建stateManager实例 SurveyorData surveyorDataSource = new SurveyorData(toleranceRecord.getSurveyorCount()); surveyorDataSource.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); - RequestSurveyorParamAuto requestSurveyorParamAuto = new RequestSurveyorParamAuto(stationId, cachedData); - - StateManager stateManager = StateManager.newInstance( - isSupportAutoMode, - requestSurveyorParamAuto, + StateManagerTj stateManager = StateManagerTj.newInstance(measureWhat, surveyorStationRecord, context, fragmentManager, lifecycleOwner, toleranceRecord, + cachedData, surveyorDataSource, surveyorDataSource, cachedData, @@ -243,7 +245,7 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment private interface ICollectCacheCallback { void onFailure(); - void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManager stateManager); + void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerTj stateManager); } public void doSurveyor() { @@ -298,33 +300,7 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment if (stateManager == null) { return; } - stateManager.stationAdjust(StationDataAdjustDialogFragment.TYPE_ANGLE_DISTANCE); - } - - /** - * 测站检测平差 - */ - public void stationCheckAdjust() { - ThreadPoolUtil.execute(() -> { - SurveyorScheduleRecord scheduleRecord = SurveyorDatabaseFactory.instance.getScheduleDataSource() - .findScheduleSync(SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null)); - if (scheduleRecord == null || SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED.equals(scheduleRecord.getStatue())) { - ToastUtils.showShort("请完成测站测量"); - return; - } - if (SurveyorScheduleConstants.STATUE_VALUE_CHECKED.equals(scheduleRecord.getStatue())) { - //经过检测 - stateManager.stationAdjustOnly(StationDataAdjustDialogFragment.TYPE_ANGLE_DISTANCE); - } else if (SurveyorScheduleConstants.STATUE_VALUE_COMPLETED.equals(scheduleRecord.getStatue())) { - //完成测量 - String error = stateManager.stationCheckOnly(); - if (!TextUtils.isEmpty(error)) { - TipsFragment.tipsOnly(getChildFragmentManager(), getViewLifecycleOwner(), requireContext(), error); - return; - } - stateManager.stationAdjustOnly(StationDataAdjustDialogFragment.TYPE_ANGLE_DISTANCE); - } - }); + stateManager.stationAdjust(); } public void goBack() { @@ -365,10 +341,10 @@ public class ComponentStationSurveyorDataListFragment extends BaseFragment } private static final String KEY_STATION_ID = "__station_id"; - public static final String TAG = ComponentStationSurveyorDataListFragment.class.getName(); + public static final String TAG = StationSurveyorRecordFragment.class.getName(); - public static ComponentStationSurveyorDataListFragment newInstance(String stationId) { - ComponentStationSurveyorDataListFragment fragment = new ComponentStationSurveyorDataListFragment(); + public static StationSurveyorRecordFragment newInstance(String stationId) { + StationSurveyorRecordFragment fragment = new StationSurveyorRecordFragment(); Bundle bundle = new Bundle(); bundle.putString(KEY_STATION_ID, stationId); fragment.setArguments(bundle); diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/IMeasureOperate.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/IMeasureOperate.java index ac6ee3c..f255be1 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/IMeasureOperate.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/IMeasureOperate.java @@ -10,9 +10,9 @@ public interface IMeasureOperate { void switchCycle(int cycleIndex); - void deleteStationAllPeroidRecord(); + void deleteStationAllCycleRecord(); - void deleteStationOnePeriodRecord(int cycleIndex); + void deleteStationOneCycleRecord(int cycleIndex); String stationCheck(); @@ -21,8 +21,10 @@ public interface IMeasureOperate { void goBack(); boolean isCurrentCycleComplete(); + int measureTypePosition(); - void refreshGoBackBtnEnable(); + int getMeasureWhat(); + void onResumeState(); + void onPauseState(); - int measureTypePosition(); } diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSettingCheckUtil.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSettingCheckUtil.java new file mode 100644 index 0000000..a25e7c6 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSettingCheckUtil.java @@ -0,0 +1,213 @@ +package com.bingce.controlnetwork.fragment.stationsurvey; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.leveling.LevelingDbFactory; +import com.bingce.controlapphelper.datasource.database.leveling.idetection.isetting.LevelIDetectionSetting; +import com.bingce.controlapphelper.datasource.database.leveling.station.LevelingStationRecord; +import com.bingce.controlapphelper.datasource.database.leveling.stationsetting.LevelingStationSettingRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.ISurveyorStationDataSource; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; +import com.bingce.controlnetwork.func.level.activity.LevelStationSettingActivity; +import com.bingce.controlnetwork.func.level.idetection.LevelIDetectionStationSettingActivity; +import com.bingce.controlnetwork.newui.stationsetting.StationSettingsActivity; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.List; + +import blankj.utilcode.util.ToastUtils; + + +public class StationSettingCheckUtil { + //请设置温度、成像、太阳方向等相关信息(App只对以上信息进行留存,不会依此对数据进行校正). + private static final String HINT = "开始测量前请先进行测站设置"; + private static final String HINT_LEVEL = "开始测量前请先进行测段设置"; + public static final String HINT_LEVEL_END = "测段结束前请先进行测段设置"; + + private boolean isCheckSuccess; + + /** + * 检测测站是否设置了棱镜相关属性,如果没有则跳转到设置界面 + */ + public void checkStationSettings(String stationId, + @NonNull Fragment fragment, + @NonNull IUIRunner runner, ICheckSuccess checkSuccess) { + if (isCheckSuccess) { + checkSuccess.onSuccess(); + return; + } + + ThreadPoolUtil.execute(() -> { + ISurveyorStationDataSource stationDataSource = + SurveyorDatabaseFactory.instance.getSurveyorStation(); + //检测温度、湿度、气压、棱镜是否设置 + SurveyorStationRecord stationRecord = stationDataSource.getRecordSync(stationId); + if (stationRecord == null) { + ToastUtils.showShort("stationRecord == null"); + return; + } + List stationItemList = stationRecord.getItems(); + if (stationItemList == null || stationItemList.isEmpty()) { + ToastUtils.showShort("stationItemList == null || stationItemList.isEmpty()"); + return; + } + boolean failure = false; + for (SurveyorPoint stationItem : stationItemList) { + if (SurveyorPoint.TYPE_STATION.equals(stationItem.getType())) { + continue; + } + if (stationItem.isWellSteel()) { + continue; + } + if (isEmpty(stationItem.getPrismHeight())) { + failure = true; + break; + } + } + if (!failure && (isEmpty(stationRecord.getTemperature()) || + isEmpty(stationRecord.getHumidity()) || + isEmpty(stationRecord.getAirPressure()) || + isEmpty(stationRecord.getInstrumentHeight()))) { + failure = true; + } + + if (failure) { + runner.runOnUI(() -> TipsWith2OptionFragment.hardTips( + fragment.getChildFragmentManager(), + fragment.getViewLifecycleOwner(), + HINT, + new TipsWith2OptionFragment.SimpleCallback() { + @Override + public void onConfirm() { +// StationSettingsFragment.start(fragment.getContext(), stationId); + StationSettingsActivity.start(fragment.requireContext(), stationId); + } + + @Override + public void onCancel() { +// if (fragment.getActivity() != null) { +// fragment.getActivity().finish(); +// } + } + })); + return; + } + + isCheckSuccess = true; + checkSuccess.onSuccess(); + + }); + + + } + + public static boolean isEmpty(String string) { + return string == null || string.isEmpty(); + } + + public interface ICheckSuccess { + void onSuccess(); + } + + /** + * 水准测站检测 + */ + public void checkStationSettingsLevel(String stationId, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + Context context, + IUIRunner runner, ICheckSuccess checkSuccessListener) { + if (isCheckSuccess) { + checkSuccessListener.onSuccess(); + return; + } + ThreadPoolUtil.execute(() -> { + LevelingStationRecord stationRecord = LevelingDbFactory.instance.getStationDataSource().getRecordSync(stationId); + if (stationRecord == null) { + ToastUtils.showShort("stationRecord == null"); + return; + } + LevelingStationSettingRecord stationSettingLatest = LevelingDbFactory.instance.getStationSettingDataSource().getLatest(stationRecord.routeId); + + if (stationSettingLatest == null || stationSettingLatest.weather == null) { + //需要设置环境设置 + runner.runOnUI(() -> showLevelSetStationSetting(fragmentManager, + lifecycleOwner, context, + HINT_LEVEL, + stationRecord.routeId, stationId, false) + ); + return; + } + + isCheckSuccess = true; + checkSuccessListener.onSuccess(); + }); + + } + + /** + * i角检测的测站设置 + */ + public void checkStationSettingsIDetection(String iDetectionId, + @NonNull AppCompatActivity activity, + @NonNull IUIRunner runner, ICheckSuccess checkSuccessListener) { + if (isCheckSuccess) { + checkSuccessListener.onSuccess(); + return; + } + ThreadPoolUtil.execute(() -> { + LevelIDetectionSetting setting = LevelingDbFactory.instance.getIDetectionSettingDataSource().getByIDetectionId(iDetectionId); + if (setting == null) { + //需要设置环境设置 + runner.runOnUI(() -> TipsWith2OptionFragment.hardTips( + activity.getSupportFragmentManager(), + activity, + HINT, + new TipsWith2OptionFragment.SimpleCallback() { + @Override + public void onConfirm() { + LevelIDetectionStationSettingActivity.launch(activity, iDetectionId); + } + }) + ); + return; + } + isCheckSuccess = true; + checkSuccessListener.onSuccess(); + }); + + } + + /** + * 提示需要进行测站设置 + */ + public static void showLevelSetStationSetting(@NonNull FragmentManager fragmentManager, + @NonNull LifecycleOwner lifecycleOwner, + Context context, + String hint, + String routeId, + String stationId, + boolean isSaveEndStation) { + TipsWith2OptionFragment.hardTips( + fragmentManager, + lifecycleOwner, + hint, + new TipsWith2OptionFragment.SimpleCallback() { + @Override + public void onConfirm() { + LevelStationSettingActivity.start(context, routeId, stationId, isSaveEndStation); + } + }); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSurveyorFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSurveyorFragment.java index 5347736..ab6ac76 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSurveyorFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/StationSurveyorFragment.java @@ -4,8 +4,6 @@ import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -17,28 +15,30 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.AutoSurveyorButtonVisibleEvent; -import com.bingce.controlapphelper.event.RefreshGoBackButton; -import com.bingce.controlapphelper.event.SurveyStateEvent; import com.bingce.controlapphelper.model.BundleConstants; -import com.bingce.controlapphelper.surveyor.test.Test; import com.bingce.controlapphelper.util.DigitalUtil; -import com.bingce.controlapphelper.util.StationUtil; import com.bingce.controlapphelper.util.SurveyorCycleUtil; import com.bingce.controlnetwork.R; import com.bingce.controlnetwork.activity.fragmentcontainer.FragmentContainerActivity; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.event.AutoSurveyorButtonVisibleEvent; +import com.bingce.controlnetwork.event.RefreshRollBackEvent; +import com.bingce.controlnetwork.event.SurveyStateEvent; import com.bingce.controlnetwork.fragment.BottomSheetSelectListFragment; -import com.bingce.controlnetwork.fragment.ComponentStationSurveyorDataListFragment; -import com.bingce.controlnetwork.fragment.SurveyorSettingsFragment; +import com.bingce.controlnetwork.fragment.StationSurveyorRecordFragment; import com.bingce.controlnetwork.fragment.base.BaseFragment; import com.bingce.controlnetwork.newui.stationsetting.StationSettingsActivity; +import com.bingce.controlnetwork.newui.stationsurveyor.ISurveyorMenuOperate; +import com.bingce.controlnetwork.newui.stationsurveyor.StationSurveyorHomeActivity; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; import com.bingce.controlnetwork.surveyor.surveyor.TestDataSelectFragment; +import com.bingce.controlnetwork.util.StationUtilPla; import com.bingce.utils.ThreadPoolUtil; import com.github.razir.progressbutton.DrawableButtonExtensionsKt; import com.github.razir.progressbutton.ProgressButtonHolderKt; @@ -50,21 +50,34 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import blankj.utilcode.util.ToastUtils; + /** - * 测站测量页面(开始测量) + * 合并观测页面 */ -public class StationSurveyorFragment extends BaseFragment { +public class StationSurveyorFragment extends BaseFragment implements ISurveyorMenuOperate { public static final String TAG = StationSurveyorFragment.class.getName(); - private ComponentStationSurveyorDataListFragment fragment; - private MenuItem goBack = null;//数据回退菜单 + private StationSurveyorRecordFragment fragment; private SurveyorStationRecord surveyorStationRecord; private int cycleIndex = 0; + private final StationSettingCheckUtil stationSettingCheckUtil=new StationSettingCheckUtil(); + + + @Override + public void onStart() { + super.onStart(); + EventBus.getDefault().register(this); + } + + @Override + public void onStop() { + super.onStop(); + EventBus.getDefault().unregister(this); + } @Subscribe(threadMode = ThreadMode.MAIN) - public void onRefreshGoBack(RefreshGoBackButton event) { - if (goBack != null) { - goBack.setEnabled(event.validate); - } + public void onRefreshGoBack(RefreshRollBackEvent event) { + setRollBackEnable(event.validate); } @Subscribe(threadMode = ThreadMode.MAIN) @@ -101,7 +114,7 @@ public class StationSurveyorFragment extends BaseFragment { } Button autoSurveyButton = getView().findViewById(R.id.auto_surveyor); if (autoSurveyButton != null) { - autoSurveyButton.setVisibility(event.isReadyAutoSurvey() && !event.isOpenAutoSurvey() + autoSurveyButton.setVisibility(event.isReadyAutoSurvey && !event.isOpenAutoSurvey ? View.VISIBLE : View.GONE); } } @@ -131,39 +144,34 @@ public class StationSurveyorFragment extends BaseFragment { } } - @Override - public void onDestroyView() { - super.onDestroyView(); - EventBus.getDefault().unregister(this); - } - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - EventBus.getDefault().register(this); - View view = inflater.inflate(R.layout.fragment_project_surveyor_station_detail_layout, container, false); - replaceFragment(); - + //1.添加测量数据显示fragment + fragment = StationSurveyorRecordFragment + .newInstance(stationId()); + getChildFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, fragment, "___station_list") + .commit(); //2.设置测量按钮 Button surveyor = view.findViewById(R.id.surveyor); if (surveyor != null) { ProgressButtonHolderKt.bindProgressButton(getViewLifecycleOwner(), surveyor); } - setSurveyorClick(view, R.id.surveyor, () -> { - if (fragment != null) { - fragment.doSurveyor(); - } - }); + setSurveyorClick(view, R.id.surveyor, this::startSurveyor); setSurveyorClick(view, R.id.auto_surveyor, () -> { - if (fragment != null) { - fragment.autoSurvey(); - } + stationSettingCheckUtil.checkStationSettings(stationId(), fragment, this, () -> { + if (fragment != null) { + fragment.autoSurvey(); + } + }); }); //3.查询测站信息 ThreadPoolUtil.execute(() -> { @@ -172,7 +180,7 @@ public class StationSurveyorFragment extends BaseFragment { .getSurveyorStation() .getRecordSync(stationId()); //监听当前测回切换 - initObserver(view); + monitorCurrentCycle(view); //监听数据变化 ToleranceDetailRecord toleranceRecord = getTolerance(surveyorStationRecord); if (toleranceRecord == null) { @@ -183,7 +191,9 @@ public class StationSurveyorFragment extends BaseFragment { if (pick == null) { return; } - int cycleCount = toleranceRecord.getCycleCount(); + + int cycleCount = StationUtilPla.getCycleCount(StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, + surveyorStationRecord, toleranceRecord); pick.setOnClickListener(v -> { ArrayList cycleList = SurveyorCycleUtil.cycleStrings(cycleCount, surveyorStationRecord != null && surveyorStationRecord.leftAndRightSurveyor); @@ -208,69 +218,33 @@ public class StationSurveyorFragment extends BaseFragment { }); }); - setHasOptionsMenu(true); return view; } - private void replaceFragment() { - //1.添加测量数据显示fragment - fragment = ComponentStationSurveyorDataListFragment - .newInstance(stationId()); - getChildFragmentManager() - .beginTransaction() - .replace(R.id.fragment_container, fragment, "___station_list") - .commit(); - } - - private void initObserver(View view) { - runOnUI(() -> { - monitorCurrentCycle(view); - //监听测站变化 - SurveyorDatabaseFactory - .instance - .getSurveyorStation() - .getLiveDataRecord(stationId()) - .observe(getViewLifecycleOwner(), - stationRecord -> { - replaceFragment(); - checkStationSettings(); - }); - - }); - } - - private void checkStationSettings() { - ThreadPoolUtil.execute(() -> MethodCheckSetting.checkStationSettings(stationId(), fragment, this::runOnUI)); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - - } - + @WorkerThread private void monitorCurrentCycle(View view) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .findSchedule(SurveyorScheduleConstants.getCurrentCycleKey(stationId(), null)) - .observe(getViewLifecycleOwner(), record -> { - TextView circleText = view.findViewById(R.id.circle_text); - //测回发生变化的时候,更新相应ui - int cycleIndex = DigitalUtil.valueOfIntString(record == null ? "0" : record.getStatue(), 0); - //更新测回名称 - if (circleText != null) { - boolean showLeftOrRight = true; - if (surveyorStationRecord != null) { - showLeftOrRight = surveyorStationRecord.leftAndRightSurveyor; + if (getActivity() != null) { + getActivity().runOnUiThread(() -> SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .findSchedule(SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT)) + .observe(getViewLifecycleOwner(), record -> { + TextView circleText = view.findViewById(R.id.circle_text); + //测回发生变化的时候,更新相应ui + int cycleIndex = DigitalUtil.string2Int(record == null ? "0" : record.getStatue(), 0); + //更新测回名称 + if (circleText != null) { + boolean showLeftOrRight = true; + if (surveyorStationRecord != null) { + showLeftOrRight = surveyorStationRecord.leftAndRightSurveyor; + } + circleText.setText(SurveyorCycleUtil.cycleName(cycleIndex, showLeftOrRight)); } - circleText.setText(SurveyorCycleUtil.cycleName(cycleIndex, showLeftOrRight)); - } - StationSurveyorFragment.this.cycleIndex = cycleIndex; - }); + StationSurveyorFragment.this.cycleIndex = cycleIndex; + })); + } } private static void setSurveyorClick(View rootView, int id, Runnable runnable) { @@ -295,88 +269,9 @@ public class StationSurveyorFragment extends BaseFragment { } } - @Override - public void onCreateOptionsMenu(@NonNull @NotNull Menu menu, @NonNull @NotNull MenuInflater inflater) { - if (Test.DEBUG) { - inflater.inflate(R.menu.menu_surveyor_station_record_data_edit_debug_pla, menu); - } else { - inflater.inflate(R.menu.menu_surveyor_station_record_data_edit_release_pla, menu); - } -// MenuItem stationCheck = menu.findItem(R.id.menu_item_station_check); -// MenuItem stationAdjust = menu.findItem(R.id.menu_item_station_adjust); - goBack = menu.findItem(R.id.menu_item_go_back); -// SurveyorDatabaseFactory -// .instance -// .getScheduleDataSource() -// .findSchedule(SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null)) -// .observe(getViewLifecycleOwner(), surveyorScheduleRecord -> { -// boolean checkStatue = false; -// boolean adjustStatue = false; -// if (surveyorScheduleRecord != null) { -// String statue = surveyorScheduleRecord.getStatue(); -// if (SurveyorScheduleConstants.STATUE_VALUE_CHECKED.equals(statue)) { -// adjustStatue = true; -// } else if (SurveyorScheduleConstants.STATUE_VALUE_COMPLETED.equals(statue)) { -// checkStatue = true; -// } else if (SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED.equals(statue)) { -// //重置提醒标识 -// String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId(); -// SurveyorDatabaseFactory -// .instance -// .getConfigDataSource() -// .set(key, ConfigConstants.VALUE_NO); -// } -// } -// //更新菜单enable -// if (stationCheck != null) { -// stationCheck.setEnabled(checkStatue); -// } -// if (stationAdjust != null) { -// stationAdjust.setEnabled(adjustStatue); -// } -// }); - } - @Override public boolean onOptionsItemSelected(@NonNull @NotNull MenuItem item) { - if (R.id.menu_item_delete_current_records == item.getItemId()) { - //删除当前测回记录 - if (surveyorStationRecord != null) { - //通知fragment - fragment.deleteByStationAndPeriod(cycleIndex); - } - } else if (R.id.menu_item_delete_all_records == item.getItemId()) { - //删除所有测回记录 - if (surveyorStationRecord != null) { - //通知fragment - fragment.deleteCurrentStationSurveyorData(); - } - } else if (R.id.menu_item_station_check == item.getItemId()) { - //测站检测,检测所有测回 - fragment.stationCheck(); - } else if (R.id.menu_item_data_source == item.getItemId()) { - //数据源 debug使用 - TestDataSelectFragment.show(getChildFragmentManager()); - } else if (R.id.menu_item_go_back == item.getItemId()) { - //回退 - fragment.goBack(); - } else if (R.id.menu_item_station_environment_prism_settings == item.getItemId()) { - //环境、棱镜设置 - StationSettingsActivity.start(requireContext(), stationId()); -// StationSettingsFragment.start(getContext(), stationId()); - } else if (R.id.menu_item_surveyor_settings == item.getItemId()) { - //测量设置 - ThreadPoolUtil.execute(() -> { - String name = StationUtil.getStationName(surveyorStationRecord); - runOnUI(() -> SurveyorSettingsFragment.start(getContext(), surveyorStationRecord.getId(), name)); - }); - } else if (R.id.menu_item_station_adjust == item.getItemId()) { - //测站平差,平差检测 - fragment.stationAdjust(); - } else if (R.id.menu_item_check_adjust == item.getItemId()) { - //检测平差 - fragment.stationCheckAdjust(); - } + return super.onOptionsItemSelected(item); } @@ -411,4 +306,74 @@ public class StationSurveyorFragment extends BaseFragment { fragment.setArguments(args); return fragment; } + + @Override + public void deleteCurrentPeriodRecords() { + //删除当前测回记录 + if (surveyorStationRecord != null) { + //通知fragment + fragment.deleteByStationAndPeriod(cycleIndex); + } + } + + @Override + public void deleteAllPeriodRecords() { + //删除所有测回记录 + if (surveyorStationRecord != null) { + //通知fragment + fragment.deleteCurrentStationSurveyorData(); + } + } + + @Override + public void test() { + //数据源 debug使用 + TestDataSelectFragment.show(getChildFragmentManager()); + } + + @Override + public void rollBack() { + //回退 + fragment.goBack(); + } + + @Override + public void stationSetting() { + //环境、棱镜设置 + StationSettingsActivity.start(fragment.requireContext(), stationId()); +// StationSettingsFragment.start(getContext(), stationId()); + } + //SurveyorSettingsFragment 测量设置 + + @Override + public void adjust() { + //测站平差,平差检测 + StationUtilPla.checkStationCanAdjust(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, new StationUtilPla.ICanAdjust() { + @Override + public void adjust(boolean isCanAdjust) { + if (!isCanAdjust) { + ToastUtils.showShort("测站未通过检测!"); + return; + } + fragment.stationAdjust(); + } + }); + } + + @Override + public void startSurveyor() { + stationSettingCheckUtil.checkStationSettings(stationId(), fragment, this, () -> { + if (fragment != null) { + fragment.doSurveyor(); + } + }); + } + + private void setRollBackEnable(boolean validate) { + FragmentActivity activity = getActivity(); + if (activity != null) { + StationSurveyorHomeActivity homeActivity = (StationSurveyorHomeActivity) activity; + homeActivity.setRollBackEnable(validate); + } + } } diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDistanceFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDistanceFragment.java deleted file mode 100644 index c1254a1..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDistanceFragment.java +++ /dev/null @@ -1,394 +0,0 @@ -package com.bingce.controlnetwork.fragment.stationsurvey.angledistance; - -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.WorkerThread; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; -import androidx.lifecycle.ViewModelProvider; -import androidx.recyclerview.widget.RecyclerView; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.RefreshGoBackButtonAloneDistance; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.data.IDistanceTypeChangeListener; -import com.bingce.controlapphelper.surveyor.data.IMeasureCache; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.data.SurveyorData; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.util.DigitalUtil; -import com.bingce.controlapphelper.util.IUIRunner; -import com.bingce.controlnetwork.adapter.MeasureAngleDistanceAdapter; -import com.bingce.controlnetwork.fragment.ComponentStationSurveyorDataListFragment; -import com.bingce.controlnetwork.fragment.base.BaseFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.totalstation.TotalStation; -import com.bingce.utils.ThreadPoolUtil; - -import org.greenrobot.eventbus.EventBus; - -import blankj.utilcode.util.ToastUtils; - -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.adapter.MeasureAngleDistanceAdapter; -import com.bingce.controlnetwork.fragment.base.BaseFragment; -import com.bingce.controlnetwork.fragment.ComponentStationSurveyorDataListFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.controlnetwork.surveyor.state.alonedistance.StateManagerAloneDistance; -import com.bingce.controlnetwork.surveyor.state.alonedistance._CheckStationState; -import com.bingce.controlnetwork.surveyor.state.alonedistance._DoCalAdjustState; -import com.bingce.controlnetwork.surveyor.state.alonedistance._IsSingleCycleCompletedState; - -/** - * 单独测距 - */ -public class MeasureDistanceFragment extends BaseFragment - implements IDistanceTypeChangeListener, ISurveyState, IMeasureOperate { - - private MeasureAngleDistanceAdapter adapter = null; - private StateManagerAloneDistance stateManager; //这里的stateManager是克隆StateManager - private RecyclerView recyclerView; - private IMeasureCache cachedData = null; - private ISurveyorData surveyedData = null; - - private String stationId() { - if (getArguments() == null) { - return null; - } - return getArguments().getString(KEY_STATION_ID); - } - - private String getWellType() { - if (getArguments() != null) { - return getArguments().getString(KEY_TYPE_ANGLE_OR_DISTANCE); - } - return null; - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - View view = inflater.inflate( - R.layout.fragment_project_surveyor_station_point_list_layout, - container, - false); - recyclerView = view.findViewById(R.id.recycler_view); - - - collectData(stationId(), - getContext(), - getChildFragmentManager(), - getViewLifecycleOwner(), - this::runOnUI, - index -> { - scrollToPosition(index); - }, - new ICollectCacheCallback() { - @Override - public void onFailure() { - } - - @Override - public void onSuccess(boolean showSlopDistance, IMeasureCache cachedData, SurveyorData surveyorData, StateManagerAloneDistance stateManager) { - onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); - } - } - ); - - return view; - } - - @WorkerThread - private void onCollectStationData( - boolean showSlopDistance, - IMeasureCache cachedData, - SurveyorData surveyorData, - StateManagerAloneDistance stateManager) { - this.stateManager = stateManager; - this.cachedData = cachedData; - this.surveyedData = surveyorData; - - //测量数据收集完毕后,就可以更新UI了 - runOnUI(() -> { - //刷新UI - if (adapter == null) { - adapter = new MeasureAngleDistanceAdapter(stationId(), - cachedData, surveyorData, surveyorData, getWellType()); - adapter.onShowSlopDistance(showSlopDistance); - if (recyclerView != null) { - recyclerView.setAdapter(adapter); - //滚动到当前目标点 - int currentItemIndex = surveyorData.currentIndex(); - scrollToPosition(currentItemIndex); - } - - adapter.setOnItemClickListener(position -> { - if (isSurveying() || isAutoSurveying()) { - ToastUtils.showShort(R.string.measuring_please_waite); - return; - } - stateManager.switchCurrentMeasurePosition(position); - scrollToPosition(position); -// adapter.notifyDataSetChanged(); - }); - } - - //监听测站数据,更新界面「平距」「斜距」显示 - SurveyorDatabaseFactory - .instance - .getSurveyorStation() - .getLiveDataRecord(stationId()) - .observe(getViewLifecycleOwner(), - surveyorStationRecord -> { - stateManager.updateStationRecord(surveyorStationRecord); - onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); - }); - }); - } - - private void scrollToPosition(int position) { - if (position >= 0 && adapter != null && position < adapter.getItemCount()) { - recyclerView.scrollToPosition(position); - adapter.notifyDataSetChanged(); - } - } - - /** - * 收集测站信息 - */ - private synchronized void collectData( - String stationId, - Context context, - FragmentManager fragmentManager, - LifecycleOwner lifecycleOwner, - IUIRunner runner, - IScrollDelegate scrollDelegate, - ICollectCacheCallback callback) { - - boolean isSupportAutoMode = TotalStation.getInstance().isSupportMotor(); - ThreadPoolUtil.execute(() -> { - //读取当前测站的当前测回--很重要 - SurveyorScheduleRecord scheduleRecord = - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .findScheduleSync(SurveyorScheduleConstants.getCurrentCycleKey(stationId, SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE)); - int defaultCycle = scheduleRecord == null ? 0 : - DigitalUtil.valueOfIntString(scheduleRecord.getStatue(), 0); - //加载测站信息 - SurveyorStationRecord surveyorStationRecord = - SurveyorDatabaseFactory - .instance - .getSurveyorStation() - .getRecordSync(stationId); - //加载对应项目 - ProjectRecord projectRecord = SurveyorDatabaseFactory - .instance - .getProjectDataSource() - .getRecord(surveyorStationRecord.getProjectId()); - if (projectRecord == null) { - callback.onFailure(); - return; - } - //加载对应限差 - ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory - .instance - .getToleranceDetailDataSource() - .getRecordSync(projectRecord.getToleranceId()); - if (toleranceRecord == null) { - callback.onFailure(); - return; - } - //创建缓存数据 - CachedDataAloneDistance cachedData = CachedDataAloneDistance.newInstance(stationId); - //是否显示斜距? - cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); - - //创建stateManager实例 - SurveyorData surveyorDataSource = new SurveyorData(ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT); - surveyorDataSource.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); - - StateManagerAloneDistance stateManager = StateManagerAloneDistance.newInstance( - isSupportAutoMode, - surveyorStationRecord, - context, - fragmentManager, - lifecycleOwner, - toleranceRecord, - surveyorDataSource, - surveyorDataSource, - cachedData, - createMeasureVm(), - scrollDelegate, - runner); - //fragment创建后立即计算当前cycle的测量状态 - runner.runOnUI(() -> - stateManager.calScheduleWhenEnterSurveyFragment(defaultCycle)); - callback.onSuccess(surveyorStationRecord.isShowSlopDistance(), cachedData, surveyorDataSource, stateManager); - }); - } - - public interface ICollectCacheCallback { - void onFailure(); - - void onSuccess(boolean showSlopDistance, IMeasureCache cachedData, SurveyorData surveyorData, StateManagerAloneDistance stateManager); - } - - @Override - public void doSurveyor() { - if (stateManager == null) { - return; - } - stateManager.doSurveyor(); - } - - @Override - public void autoSurvey() { - if (stateManager == null) { - return; - } - stateManager.doAutoSurveyor(); - } - - @Override - public void switchCycle(int cycleIndex) { - if (stateManager == null) { - return; - } - stateManager.switch2Cycle(cycleIndex); - } - - @Override - public void deleteStationAllPeroidRecord() { - if (stateManager == null) { - return; - } - stateManager.deleteCurrentStationSurveyorData(); - } - - @Override - public void deleteStationOnePeriodRecord(int cycleIndex) { -// if (stateManager == null) { -// return; -// } -// stateManager.deleteCurrentStationSurveyorData(cycleIndex); - } - - @Override - public String stationCheck() { - if (stateManager == null) { - return null; - } - return _CheckStationState._stationCheckAloneDistance(stationId(), stateManager.getToleranceRecord(), stateManager.getCachedData()); - } - - @Override - public void stationAdjust() { - if (stateManager == null) { - return; - } - _DoCalAdjustState.doCalAdjust(stationId(), stateManager.getCachedData(), requireContext(), - getChildFragmentManager(), getViewLifecycleOwner()); -// stateManager.stationAdjust(); - } - - @Override - public void goBack() { - if (stateManager == null) { - return; - } - stateManager.moveBack(); - } - - @Override - public void onShowSlopDistance(boolean value) { - if (cachedData != null) { - cachedData.onShowSlopDistance(value); - } - if (surveyedData != null) { - surveyedData.onShowSlopDistance(value); - } - if (adapter != null) { - adapter.onShowSlopDistance(value); - adapter.notifyItemRangeChanged(0, adapter.getItemCount()); - } - } - - @Override - public boolean isSurveying() { - if (stateManager != null) { - return stateManager.isSurveying(); - } - return false; - } - - @Override - public boolean isAutoSurveying() { - if (stateManager != null) { - return stateManager.isAutoSurveying(); - } - return false; - } - - private static final String KEY_STATION_ID = "__station_id"; - private static final String KEY_TYPE_ANGLE_OR_DISTANCE = "__key_type_angle_or_distance"; - public static final String TAG = ComponentStationSurveyorDataListFragment.class.getName(); - - public static MeasureDistanceFragment newInstance(String stationId, String typeAngleOrDistance) { - MeasureDistanceFragment fragment = new MeasureDistanceFragment(); - Bundle bundle = new Bundle(); - bundle.putString(KEY_STATION_ID, stationId); - bundle.putString(KEY_TYPE_ANGLE_OR_DISTANCE, typeAngleOrDistance); - fragment.setArguments(bundle); - return fragment; - } - - @Override - public boolean isCurrentCycleComplete() { - if (stateManager == null) - return false; - boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( - stationId(), - StateManagerAloneDistance.CYCLE_INDEX_DEFAULT, - stateManager.getCachedData(), ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT); - return completed; - } - - @Override - public void refreshGoBackBtnEnable() { - if (stateManager == null || stateManager.getCachedData().pointCount() == 0) { - EventBus.getDefault().post(new RefreshGoBackButtonAloneDistance(false)); - return; - } - stateManager.refreshGoBackBtnEnable(); - } - - @Override - public int measureTypePosition() { - return MeasureFragment.POSITION_DISTANCE_MEASURE; - } - - private MeasureVm createMeasureVm() { - return new ViewModelProvider(requireParentFragment()).get(MeasureVm.class); - } - - -} - - - diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureFragment.java deleted file mode 100644 index 53d79e6..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureFragment.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.bingce.controlnetwork.fragment.stationsurvey.angledistance; - -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.model.BundleConstants; -import com.bingce.controlapphelper.util.StationUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.activity.fragmentcontainer.FragmentContainerActivity; -import com.bingce.controlnetwork.adapter.MeasureAngleDistanceAdapter; -import com.bingce.controlnetwork.fragment.SurveyorSettingsFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.MethodCheckSetting; -import com.bingce.controlnetwork.fragment.stationsurvey.base.MeasureBaseFragment; -import com.bingce.controlnetwork.newui.stationsetting.StationSettingsActivity; -import com.bingce.controlnetwork.surveyor.surveyor.TestDataSelectFragment; -import com.bingce.utils.ThreadPoolUtil; - -import org.jetbrains.annotations.NotNull; - -/** - * 测站测量页面(开始测量) - */ -public class MeasureFragment extends MeasureBaseFragment { - public static final String TAG = MeasureFragment.class.getName(); - - //方位观测fragment的在adapter的索引 - public static final int POSITION_DIRECTION_MEASURE = 0; - public static final int POSITION_DISTANCE_MEASURE = 1; - - @Override - protected boolean isShowSelectCycle(int position) { - return POSITION_DIRECTION_MEASURE == position; - } - - @Override - protected int defaultPageIndex() { - return POSITION_DIRECTION_MEASURE; - } - - @Override - protected void addFragmentsTabs(Runnable runnable) { - MeasureDefaultFragment fragmentAngle = MeasureDefaultFragment.newInstance(stationId(), MeasureAngleDistanceAdapter.TYPE_ANGLE); - fragments.add(fragmentAngle); - MeasureDistanceFragment fragmentDistance = MeasureDistanceFragment.newInstance(stationId(), MeasureAngleDistanceAdapter.TYPE_DISTANCE); - fragments.add(fragmentDistance); - - tabs.add(Tools.getString(R.string.azimuth_observation)); - tabs.add(Tools.getString(R.string.alone_measure_distance)); - runnable.run(); - } - - @Override - protected boolean isAloneDistancePage(int pageIndex) { - return POSITION_DISTANCE_MEASURE == pageIndex; - } - - @Override - protected String getCurrentPageCycleKey() { - if (mBinding.vp.getCurrentItem() == POSITION_DIRECTION_MEASURE) { - return SurveyorScheduleConstants.getCurrentCycleKey(stationId(), null); - } else { - return SurveyorScheduleConstants.getCurrentCycleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE); - } - } - - @Override - protected String getScheduleIdForAllCycle() { - int currentItem = mBinding.vp.getCurrentItem(); - String scheduleId; - if (!isAloneDistancePage(currentItem)) { - scheduleId = SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null); - } else { - scheduleId = SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE); - } - return scheduleId; - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = super.onCreateView(inflater, container, savedInstanceState); - initObserver(); - return view; - } - - private void initObserver() { - //监听测站变化 - SurveyorDatabaseFactory - .instance - .getSurveyorStation() - .getLiveDataRecord(stationId()) - .observe(getViewLifecycleOwner(), - stationRecord -> { - checkStationSettings(); - }); - -// SurveyorScheduleConstants.getCurrentCycleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE); - monitorCurrentCycle(SurveyorScheduleConstants.getCurrentCycleKey(stationId(), null)); - } - - private void checkStationSettings() { - ThreadPoolUtil.execute(() -> MethodCheckSetting.checkStationSettings(stationId(), this, this::runOnUI)); - } - - @Override - public void onPrepareOptionsMenu(@NonNull Menu menu) { - super.onPrepareOptionsMenu(menu); - //删除当前测回记录 - menu.findItem(R.id.menu_item_delete_current_records).setEnabled(deleteSingleCycleEnable()); - } - - @Override - public boolean onOptionsItemSelected(@NonNull @NotNull MenuItem item) { - if (R.id.menu_item_delete_current_records == item.getItemId()) { - //删除当前测回记录 - if (surveyorStationRecord != null && currentFragment != null) { - //通知fragment - currentFragment.deleteStationOnePeriodRecord(cycleIndex); - } - } else if (R.id.menu_item_delete_all_records == item.getItemId()) { - //删除所有测回记录 - if (surveyorStationRecord != null && currentFragment != null) { - //通知fragment - currentFragment.deleteStationAllPeroidRecord(); - } - } else if (R.id.menu_item_station_check == item.getItemId() && currentFragment != null) { - //测站检测 被检测平差替代 - stationCheckBefore(); - } else if (R.id.menu_item_data_source == item.getItemId()) { - //数据源 debug使用 - TestDataSelectFragment.show(getChildFragmentManager()); - } else if (R.id.menu_item_go_back == item.getItemId() && currentFragment != null) { - //回退 - currentFragment.goBack(); - } else if (R.id.menu_item_station_environment_prism_settings == item.getItemId()) { - //环境、棱镜设置 - StationSettingsActivity.start(requireContext(), stationId()); -// StationSettingsFragment.start(getContext(), stationId()); - } else if (R.id.menu_item_surveyor_settings == item.getItemId()) { - //测量设置 设置是否显示平距 - ThreadPoolUtil.execute(() -> { - String name = StationUtil.getStationName(surveyorStationRecord); - runOnUI(() -> SurveyorSettingsFragment.start(getContext(), surveyorStationRecord.getId(), name)); - }); - } else if (R.id.menu_item_check_adjust == item.getItemId() && currentFragment != null) { - //检测平差 - stationCheckAdjustBefore(); - } - return super.onOptionsItemSelected(item); - } - - private boolean deleteSingleCycleEnable() { - return currentFragment != null && currentFragment instanceof MeasureDefaultFragment; - } - - public static void start(Context context, String surveyorStationId, String surveyorStationName) { - Bundle bundle = new Bundle(); - bundle.putString(BundleConstants.KEY_SURVEYOR_STATION_ID, surveyorStationId); - FragmentContainerActivity.start(context, TAG, surveyorStationName, bundle); - } - - public static Fragment newInstance(Bundle args) { - Fragment fragment = new MeasureFragment(); - fragment.setArguments(args); - return fragment; - } - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/BaseFragmentLazy.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/BaseFragmentLazy.java new file mode 100644 index 0000000..840e65e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/BaseFragmentLazy.java @@ -0,0 +1,154 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.base; + + +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.IdRes; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +/** + * Created by dasu on 2016/9/27. + *

+ * Fragment基类,封装了懒加载的实现 + *

+ * 1、Viewpager + Fragment情况下,fragment的生命周期因Viewpager的缓存机制而失去了具体意义 + * 该抽象类自定义新的回调方法,当fragment可见状态改变时会触发的回调方法,和 Fragment 第一次可见时会回调的方法 + * + * @see #onFragmentVisibleChange(boolean) + * @see #onFragmentFirstVisible() + */ +public abstract class BaseFragmentLazy extends Fragment { + + private boolean isFragmentVisible; + private boolean isReuseView; + private boolean isFirstVisible; + private View rootView; + + + //setUserVisibleHint()在Fragment创建时会先被调用一次,传入isVisibleToUser = false + //如果当前Fragment可见,那么setUserVisibleHint()会再次被调用一次,传入isVisibleToUser = true + //如果Fragment从可见->不可见,那么setUserVisibleHint()也会被调用,传入isVisibleToUser = false + //总结:setUserVisibleHint()除了Fragment的可见状态发生变化时会被回调外,在new Fragment()时也会被回调 + //如果我们需要在 Fragment 可见与不可见时干点事,用这个的话就会有多余的回调了,那么就需要重新封装一个 + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + //setUserVisibleHint()有可能在fragment的生命周期外被调用 + if (rootView == null) { + return; + } + if (isFirstVisible && isVisibleToUser) { + onFragmentFirstVisible(); + isFirstVisible = false; + } + if (isVisibleToUser) { + onFragmentVisibleChange(true); + isFragmentVisible = true; + return; + } + if (isFragmentVisible) { + isFragmentVisible = false; + onFragmentVisibleChange(false); + } + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + initVariable(); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + //如果setUserVisibleHint()在rootView创建前调用时,那么 + //就等到rootView创建完后才回调onFragmentVisibleChange(true) + //保证onFragmentVisibleChange()的回调发生在rootView创建完成之后,以便支持ui操作 + if (rootView == null) { + rootView = view; + if (getUserVisibleHint()) { + if (isFirstVisible) { + onFragmentFirstVisible(); + isFirstVisible = false; + } + onFragmentVisibleChange(true); + isFragmentVisible = true; + } + } + super.onViewCreated(isReuseView ? rootView : view, savedInstanceState); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + initVariable(); + } + + private void initVariable() { + isFirstVisible = true; + isFragmentVisible = false; + rootView = null; + isReuseView = true; + } + + /** + * 设置是否使用 view 的复用,默认开启 + * view 的复用是指,ViewPager 在销毁和重建 Fragment 时会不断调用 onCreateView() -> onDestroyView() + * 之间的生命函数,这样可能会出现重复创建 view 的情况,导致界面上显示多个相同的 Fragment + * view 的复用其实就是指保存第一次创建的 view,后面再 onCreateView() 时直接返回第一次创建的 view + * + * @param isReuse + */ + protected void reuseView(boolean isReuse) { + isReuseView = isReuse; + } + + /** + * 去除setUserVisibleHint()多余的回调场景,保证只有当fragment可见状态发生变化时才回调 + * 回调时机在view创建完后,所以支持ui操作,解决在setUserVisibleHint()里进行ui操作有可能报null异常的问题 + *

+ * 可在该回调方法里进行一些ui显示与隐藏,比如加载框的显示和隐藏 + * + * @param isVisible true 不可见 -> 可见 + * false 可见 -> 不可见 + */ + protected void onFragmentVisibleChange(boolean isVisible) { + + } + + /** + * 在fragment首次可见时回调,可在这里进行加载数据,保证只在第一次打开Fragment时才会加载数据, + * 这样就可以防止每次进入都重复加载数据 + * 该方法会在 onFragmentVisibleChange() 之前调用,所以第一次打开时,可以用一个全局变量表示数据下载状态, + * 然后在该方法内将状态设置为下载状态,接着去执行下载的任务 + * 最后在 onFragmentVisibleChange() 里根据数据下载状态来控制下载进度ui控件的显示与隐藏 + */ + protected void onFragmentFirstVisible() { + + } + + protected boolean isFragmentVisible() { + return isFragmentVisible; + } + + final protected void runOnUI(Runnable runnable) { + if (getActivity() == null) { + return; + } + getActivity().runOnUiThread(runnable); + } + + final protected T findViewById(@IdRes int id) { + if (getActivity() == null) { + return null; + } + return getActivity().findViewById(id); + } +} + diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/MeasureBaseFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/MeasureBaseFragment.java index 6b7f83f..1c38531 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/MeasureBaseFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/base/MeasureBaseFragment.java @@ -305,7 +305,7 @@ public abstract class MeasureBaseFragment extends BaseFragment { //切换tab测回可能会变刷新当前fragment refreshCycleAndFragment(); - currentFragment.refreshGoBackBtnEnable(); +// currentFragment.refreshGoBackBtnEnable(); } @Override diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseFragment.kt b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseFragment.kt index 93a0ee1..abc141f 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseFragment.kt +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseFragment.kt @@ -155,7 +155,7 @@ class MeasureHeightTraverseFragment : MeasureBaseFragment() { //删除当前测回记录 if (surveyorStationRecord != null && currentFragment != null) { //通知fragment - currentFragment.deleteStationOnePeriodRecord(getCurrentMeasurePos()) + currentFragment.deleteStationOneCycleRecord(getCurrentMeasurePos()) } } else if (R.id.menu_item_delete_all_records == item.itemId) { //删除所有测回记录 @@ -185,7 +185,7 @@ class MeasureHeightTraverseFragment : MeasureBaseFragment() { ) } } - } else if (R.id.menu_item_check_adjust == item.itemId && currentFragment != null) { + } else if (R.id.menu_item_station_adjust == item.itemId && currentFragment != null) { //检测平差 stationCheckAdjustBefore() } @@ -220,7 +220,7 @@ class MeasureHeightTraverseFragment : MeasureBaseFragment() { object : TipsWith2OptionFragment.SimpleCallback() { override fun onConfirm() { for (fragmentI in fragments) { - fragmentI.deleteStationAllPeroidRecord() + fragmentI.deleteStationAllCycleRecord() } } }) diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseSubFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseSubFragment.java index 89d7499..0e48a66 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseSubFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/heighttraverse/MeasureHeightTraverseSubFragment.java @@ -18,7 +18,6 @@ import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.RefreshGoBackButton; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; import com.bingce.controlapphelper.surveyor.data.CachedDataHeightTraverse; @@ -32,7 +31,6 @@ import com.bingce.controlapphelper.util.IUIRunner; import com.bingce.controlapphelper.util.IdUtil; import com.bingce.controlnetwork.R; import com.bingce.controlnetwork.adapter.MeasureHeightTraverseAdapter; -import com.bingce.controlnetwork.fragment.ComponentStationSurveyorDataListFragment; import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; import com.bingce.controlnetwork.fragment.base.BaseLazyFragment; import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; @@ -42,8 +40,6 @@ import com.bingce.controlnetwork.surveyor.state.heighttraverse.StateManagerHeigh import com.bingce.totalstation.TotalStation; import com.bingce.utils.ThreadPoolUtil; -import org.greenrobot.eventbus.EventBus; - /** * 测角测距 */ @@ -283,7 +279,7 @@ public class MeasureHeightTraverseSubFragment extends BaseLazyFragment } @Override - public void deleteStationAllPeroidRecord() { + public void deleteStationAllCycleRecord() { if (stateManager == null) { return; } @@ -291,11 +287,12 @@ public class MeasureHeightTraverseSubFragment extends BaseLazyFragment } @Override - public void deleteStationOnePeriodRecord(int positionFragment) { + public void deleteStationOneCycleRecord(int cycleIndex) { if (stateManager == null) { return; } - stateManager.deleteCurrentStationSurveyorData(positionFragment); + // TODO: 2024/8/30 + stateManager.deleteCurrentStationSurveyorData(0); } @Override @@ -345,20 +342,27 @@ public class MeasureHeightTraverseSubFragment extends BaseLazyFragment return true; } - @Override - public void refreshGoBackBtnEnable() { - if (stateManager == null || stateManager.getCachedData().pointCount() == 0) { - EventBus.getDefault().post(new RefreshGoBackButton(false)); - return; - } - stateManager.refreshGoBackBtnEnable(); - } @Override public int measureTypePosition() { return getBackOrFrontPosition(); } + @Override + public int getMeasureWhat() { + return 0; + } + + @Override + public void onResumeState() { + + } + + @Override + public void onPauseState() { + + } + @Override public void onShowSlopDistance(boolean value) { if (cachedData != null) { @@ -399,7 +403,7 @@ public class MeasureHeightTraverseSubFragment extends BaseLazyFragment private static final String KEY_STATION_ID = "__station_id"; private static final String KEY_TYPE_BACK_OR_FRONT = "__KEY_TYPE_BACK_OR_FRONT"; - public static final String TAG = ComponentStationSurveyorDataListFragment.class.getName(); + public static final String TAG = MeasureHeightTraverseSubFragment.class.getName(); public static MeasureHeightTraverseSubFragment newInstance(String stationId, int frontOrBack) { MeasureHeightTraverseSubFragment fragment = new MeasureHeightTraverseSubFragment(); diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateDistanceFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateDistanceFragment.java new file mode 100644 index 0000000..5473b4d --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateDistanceFragment.java @@ -0,0 +1,476 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.separate; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.datasource.database.ProjectTypeValue; +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.ViewItemType; +import com.bingce.controlapphelper.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; +import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; +import com.bingce.controlnetwork.fragment.stationsurvey.base.BaseFragmentLazy; +import com.bingce.controlnetwork.surveyor.data.CachedData; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.wellDistance.StateManagerWell; +import com.bingce.controlnetwork.surveyor.state.wellDistance._CheckToleranceState; +import com.bingce.utils.ThreadPoolUtil; + +import blankj.utilcode.util.ToastUtils; +import com.bingce.controlnetwork.surveyor.state.wellDistance.IWeatherShowDialogListener; + + +/** + * 井定向钢丝测距或者单独测距 + */ +public class StationSurveyorSeparateDistanceFragment extends BaseFragmentLazy + implements IDistanceTypeChangeListener, ISurveyState, IMeasureOperate { + + private StationSurveyorSepatateAdapter adapter = null; + private StateManagerWell stateManager; //这里的stateManager是克隆StateManager + private RecyclerView recyclerView; + private ICachedData cachedData = null; + private ISurveyorData surveyedData = null; + private ISurveyState surveyState; + + private final IWeatherShowDialogListener weatherShowDialogListener = (stationId, currentCycleIndex, pointId, beforeOrAfter, msg) -> { + if (getView() == null) return; + TipsWith2OptionFragment + .tips( + getChildFragmentManager(), + getViewLifecycleOwner(), + Tools.getString(R.string.confirm), + Tools.getString(R.string.cancel), + msg, + new TipsWith2OptionFragment.SimpleCallback() { + @Override + public void onConfirm() { +// DistanceWeatherSettingTjActivity.launch(requireContext(), stationId, currentCycleIndex, pointId, beforeOrAfter); + } + + @Override + public void onIgnore() { + super.onIgnore(); + } + } + ); + }; + + private String stationId() { + if (getArguments() == null) { + return null; + } + return getArguments().getString(KEY_STATION_ID); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate( + R.layout.fragment_project_surveyor_station_point_list_layout, + container, + false); + recyclerView = view.findViewById(R.id.recycler_view); + + String stationId = stationId(); + if (stationId != null) { + //收集信息 + collectData(stationId, + getContext(), + getChildFragmentManager(), + getViewLifecycleOwner(), + this::runOnUI, + this::scrollToPosition, + new ICollectCacheCallback() { + @Override + public void onFailure() { + + } + + @Override + public void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerWell stateManager) { + onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); + surveyState = stateManager; + } + } + ); + } + + return view; + } + + @WorkerThread + private void onCollectStationData( + boolean showSlopDistance, + ICachedData cachedData, + SurveyorData surveyorData, + StateManagerWell stateManager) { + + this.stateManager = stateManager; + this.cachedData = cachedData; + this.surveyedData = surveyorData; + + //更新完棱镜类型刷新页面 +// stateManager.setRefreshFragmentUiListener(() -> changeCacheDataAndRefreshUi(stationId())); + + + //测量数据收集完毕后,就可以更新UI了 + runOnUI(() -> { + if (getView() == null) { + return; + } + //刷新UI + if (adapter == null) { + adapter = new StationSurveyorSepatateAdapter(stateManager.getProjectType(), stationId(), + cachedData, stateManager.getTolreanceRecord(), surveyorData, surveyorData, ViewItemType.aloneDistanceMeasure); + adapter.onShowSlopDistance(showSlopDistance); + if (recyclerView != null) { + recyclerView.setAdapter(adapter); + //滚动到当前目标点 + int currentItemIndex = surveyorData.currentIndex(); + scrollToPosition(0, currentItemIndex); + } + + adapter.setOnItemClickListener(position -> { + if (isSurveying()) { + ToastUtils.showShort("正在测量中,请稍后..."); + return; + } + stateManager.setCurrentIndex(position); + stateManager.setCurrentCycleIndex(0); + stateManager.refeshRollBackBtn(); + + scrollToPosition(0, position); + }); + + } + + //监听测站数据,更新界面「平距」「斜距」显示 + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getLiveDataRecord(stationId()) + .observe(getViewLifecycleOwner(), + surveyorStationRecord -> onShowSlopDistance(surveyorStationRecord.isShowSlopDistance())); + }); + } + + private void scrollToPosition(int cycleIndex, int position) { + if (position >= 0 && adapter != null && position < adapter.getItemCount()) { + recyclerView.scrollToPosition(position); + adapter.notifyDataSetChanged(); + } + } + + /** + * 收集测站信息 + */ + private void collectData( + String stationId, + Context context, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner runner, + ISurveyorDataScrollDelegate scrollDelegate, + ICollectCacheCallback callback) { + if (callback == null) { + return; + } + ThreadPoolUtil.execute(() -> { + //加载测站信息 + SurveyorStationRecord stationRecord = + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + //加载对应项目 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(stationRecord.getProjectId()); + if (projectRecord == null) { + callback.onFailure(); + return; + } + //加载对应限差 + ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + if (toleranceRecord == null) { + callback.onFailure(); + return; + } + //创建缓存数据 + CachedDataPointType cachedDataPointType = CachedDataPointType.ALONE_MEASURE_DISTANCE_POINT; + if (isConnection(stationRecord.projectType)) { + //如果是联系列表收集的是钢丝 + cachedDataPointType = CachedDataPointType.STEEL_POINT; + } + CachedData cachedData = CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE, cachedDataPointType, stationRecord.isAutoClose(), + stationRecord.isLeftAndRightSurveyor(), + stationId, toleranceRecord); + if (cachedData == null) { + callback.onFailure(); + return; + } + + //是否显示斜距? + cachedData.onShowSlopDistance(stationRecord.isShowSlopDistance()); + //创建stateManager实例 + SurveyorData surveyorDataSource = new SurveyorData(ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT); + surveyorDataSource.onShowSlopDistance(stationRecord.isShowSlopDistance()); + + // + + StateManagerWell stateManager = StateManagerWell.newInstance( + stationRecord, + context, + fragmentManager, + lifecycleOwner, + toleranceRecord, + cachedData, + surveyorDataSource, + surveyorDataSource, + cachedData, + scrollDelegate, + runner, + weatherShowDialogListener + ); + + callback.onSuccess(stationRecord.isShowSlopDistance(), cachedData, surveyorDataSource, stateManager); + }); + } + + /** + * 改变cacheData并刷新Ui + */ + private void changeCacheDataAndRefreshUi(String stationId) { + ThreadPoolUtil.execute(() -> { + //加载测站信息 + SurveyorStationRecord surveyorStationRecord = + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + //加载对应项目 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(surveyorStationRecord.getProjectId()); + if (projectRecord == null) { + return; + } + //加载对应限差 + ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + if (toleranceRecord == null) { + return; + } + //创建缓存数据 + CachedDataPointType cachedDataPointType = CachedDataPointType.ALONE_MEASURE_DISTANCE_POINT; + if (isConnection(surveyorStationRecord.projectType)) { + cachedDataPointType = CachedDataPointType.STEEL_POINT; + } + CachedData cachedData = CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, cachedDataPointType, surveyorStationRecord.isAutoClose(), + surveyorStationRecord.isLeftAndRightSurveyor(), + stationId, toleranceRecord); + if (cachedData != null) { + //是否显示斜距? + cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); +// stateManager.setCachedData(cachedData); + adapter.setCachedData(cachedData); + runOnUI(() -> adapter.notifyDataSetChanged()); + } + }); + } + + public interface ICollectCacheCallback { + void onFailure(); + + void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerWell stateManager); + } + + @Override + public void doSurveyor() { + if (stateManager == null) { + return; + } + stateManager.doSurveyor(); + } + + @Override + public void autoSurvey() { + + + } + + @Override + public void switchCycle(int cycleIndex) { + if (stateManager == null) { + return; + } + stateManager.switch2Cycle(cycleIndex); + } + + @Override + public void deleteStationAllCycleRecord() { + if (stateManager == null) { + return; + } + stateManager.deletePointAllCycleData(); + } + + @Override + public void deleteStationOneCycleRecord(int cycleIndex) { + if (stateManager == null) { + return; + } + stateManager.deletePointCurrentCycleData(); + } + + @Override + public String stationCheck() { + if (stateManager == null) { + return null; + } + stateManager.stationCheck(); + return null; + } + + @Override + public void stationAdjust() { + if (stateManager != null) { + stateManager.stationAdjust(); + } + } + + @Override + public void goBack() { + if (stateManager == null) { + return; + } + stateManager.moveBack(); + } + + @Override + public void onShowSlopDistance(boolean value) { + if (cachedData != null) { + cachedData.onShowSlopDistance(value); + } + if (surveyedData != null) { + surveyedData.onShowSlopDistance(value); + } + if (adapter != null) { + adapter.onShowSlopDistance(value); + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + } + } + + @Override + public boolean isSurveying() { + if (surveyState != null) { + return surveyState.isSurveying(); + } + return false; + } + + @Override + public boolean isAutoSurveying() { + if (surveyState != null) { + return surveyState.isAutoSurveying(); + } + return false; + } + + private static final String KEY_STATION_ID = "__station_id"; + private static final String KEY_WELL_TYPE = "__well_type"; + public static final String TAG = StationSurveyorSeparateDistanceFragment.class.getName(); + + public static StationSurveyorSeparateDistanceFragment newInstance(String stationId) { + StationSurveyorSeparateDistanceFragment fragment = new StationSurveyorSeparateDistanceFragment(); + Bundle bundle = new Bundle(); + bundle.putString(KEY_STATION_ID, stationId); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public boolean isCurrentCycleComplete() { + if (stateManager == null) + return false; + return _CheckToleranceState.isCompleteAllPointForAloneDistance(stationId(), 0, stateManager.getCachedData()); + } + + @Override + public int measureTypePosition() { + return 0; + } + + @Override + public int getMeasureWhat() { + return StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE; + } + + @Override + public void onResumeState() { + if (stateManager != null) { + stateManager.resume(); + } + } + + @Override + public void onPauseState() { + if (stateManager != null) { + stateManager.quite(); + } + } + + @Override + protected void onFragmentFirstVisible() { + if (stateManager != null) + stateManager.calScheduleWhenEnterSurveyFragment(); +// if (stateManager != null) +// stateManager.enter(StateType.idle); + } + + /** + * 是否联系测量 + * + * @param projectType 项目类型 + * @return + */ + private boolean isConnection(String projectType) { + return ProjectTypeValue.CONNECTION.equals(projectType); + } + +} + + + diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateFragment.java new file mode 100644 index 0000000..36de239 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateFragment.java @@ -0,0 +1,375 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.separate; + + +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.Button; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.bingce.controlapphelper.model.BundleConstants; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.activity.fragmentcontainer.FragmentContainerActivity; +import com.bingce.controlnetwork.event.RefreshRollBackEvent; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.fragment.base.BaseFragment; +import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; +import com.bingce.controlnetwork.newui.stationsetting.StationSettingsActivity; +import com.bingce.controlnetwork.newui.stationsurveyor.ISurveyorMenuOperate; +import com.bingce.controlnetwork.newui.stationsurveyor.StationSurveyorHomeActivity; +import com.bingce.controlnetwork.surveyor.surveyor.TestDataSelectFragment; +import com.bingce.controlnetwork.util.StationSettingCheckUtil; +import com.flyco.tablayout.SlidingTabLayout; +import com.github.razir.progressbutton.DrawableButtonExtensionsKt; +import com.github.razir.progressbutton.ProgressButtonHolderKt; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; + + +/** + * 测站测量页面(开始测量) + * 水平角,垂直角,距离分开观测 + */ +public class StationSurveyorSeparateFragment extends BaseFragment implements ISurveyorMenuOperate { + public static final String TAG = StationSurveyorSeparateFragment.class.getName(); + +// private SurveyorStationRecord surveyorStationRecord; + + //方位观测fragment的在adapter的索引 + public static final int POSITION_ANGLE_HOR = 0; + public static final int POSITION_ANGLE_VER = 1; + public static final int POSITION_DISTANCE_MEASURE = 2; + private final String[] tabs = { + "水平角观测", "垂直角观测", "距离观测" + }; + + private List fragments; + private IMeasureOperate currentFragment; + + private ViewPager vp; + + private final StationSettingCheckUtil stationSettingCheckUtil = new StationSettingCheckUtil(); + + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onRefreshGoBack(RefreshRollBackEvent event) { + if (vp != null) { + int currentItem = vp.getCurrentItem(); + if (currentItem == POSITION_ANGLE_HOR) { + setRollBackEnable(event.validate); + } else if (currentItem == POSITION_DISTANCE_MEASURE) { + setRollBackEnable(event.validate); + } + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSurveyorStateChanged(SurveyStateEvent event) { + if (getView() == null) { + return; + } + Button surveyorButton = getView().findViewById(R.id.surveyor); + if (surveyorButton == null) { + return; + } + if (event.isIdle() || event.isSuccess() || event.isCompleted()) { + DrawableButtonExtensionsKt.hideProgress(surveyorButton, R.string.start_surveyor); + } else if (event.isSurveying()) { + DrawableButtonExtensionsKt.showProgress(surveyorButton, progressParams -> { + progressParams.setButtonTextRes(R.string.tips_surveying); + progressParams.setProgressColor(Color.WHITE); + return null; + }); + } else if (event.isFailure()) { + DrawableButtonExtensionsKt.hideProgress(surveyorButton, R.string.tips_surveyor_failure_and_retry); + } + + boolean enable = event.isIdle() || event.isFailure() || event.isSuccess(); + + setSurveyorEnable(getView(), R.id.surveyor, enable); + } + + + private String stationId() { + if (getArguments() == null) { + return null; + } + return getArguments().getString(BundleConstants.KEY_SURVEYOR_STATION_ID); + } + + @Override + public void onStart() { + super.onStart(); + EventBus.getDefault().register(this); + } + + @Override + public void onStop() { + super.onStop(); + EventBus.getDefault().unregister(this); + } + + @Override + public void onResume() { + super.onResume(); + //测量界面保持常亮 + if (getActivity() != null) { + getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + if (currentFragment != null) { + currentFragment.onResumeState(); + } + } + + @Override + public void onPause() { + super.onPause(); + //清除界面常亮 + if (getActivity() != null) { + getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + if (currentFragment != null) { + currentFragment.onPauseState(); + } + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_station_surveyor_separate, + container, + false); + //2.设置测量按钮 + Button surveyor = view.findViewById(R.id.surveyor); + if (surveyor != null) { + ProgressButtonHolderKt.bindProgressButton(getViewLifecycleOwner(), surveyor); + } + setClick(view, R.id.surveyor, this::startSurveyor); + + setHasOptionsMenu(true); + + return view; + } + + private void initData() { +// ThreadPoolUtil.execute(() -> { +// surveyorStationRecord = TjDbFactory +// .instance +// .getSurveyorStation() +// .getRecordSync(stationId()); +// //监听数据变化 +// ToleranceDetailRecordTj toleranceRecord = getTolerance(surveyorStationRecord); +// if (toleranceRecord == null) { +// return; +// } +// int cycleCount = StationUtilTj.getCycleCount(surveyorStationRecord, toleranceRecord); +// cycleList = SurveyorCycleUtil.cycleStrings(cycleCount, +// surveyorStationRecord != null && surveyorStationRecord.leftAndRightSurveyor); +// }); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initViewPager(view); + initData(); + } + + private void initViewPager(View view) { + + fragments = new ArrayList<>(); + fragments.add(StationSurveyorSeparateHorAngleFragment.newInstance(stationId())); + fragments.add(StationSurveyorSeparateVerAngleFragment.newInstance(stationId())); + fragments.add(StationSurveyorSeparateDistanceFragment.newInstance(stationId())); + + SlidingTabLayout tabLayout = view.findViewById(R.id.tabLayout); + vp = view.findViewById(R.id.vp); + vp.setOffscreenPageLimit(3); + vp.setAdapter(new MyPagerAdapter(getChildFragmentManager())); + tabLayout.setViewPager(vp); + + vp.setCurrentItem(POSITION_ANGLE_HOR); + currentFragment = fragments.get(POSITION_ANGLE_HOR); + + vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + currentFragment = fragments.get(position); + + //刷新按钮状态 + boolean currentCycleComplete = currentFragment.isCurrentCycleComplete(); + if (currentCycleComplete) { + SurveyStateEvent.postCompleted(); + } else { + SurveyStateEvent.postIdle(); + } + + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + + } + + + private static void setClick(View rootView, int id, Runnable runnable) { + View view = rootView.findViewById(id); + if (view != null) { + view.setOnClickListener(v -> runnable.run()); + } + } + + private static void setSurveyorEnable(View rootView, int id, boolean enable) { + if (rootView == null) { + return; + } + View view = rootView.findViewById(id); + if (view != null) { + view.setEnabled(enable); + if (enable) { + view.setAlpha(1); + } else { + view.setAlpha(.4f); + } + } + } + + private void setRollBackEnable(boolean validate) { + FragmentActivity activity = getActivity(); + if (activity != null) { + StationSurveyorHomeActivity homeActivity = (StationSurveyorHomeActivity) activity; + homeActivity.setRollBackEnable(validate); + } + } + + public static void start(Context context, String surveyorStationId, String surveyorStationName) { + Bundle bundle = new Bundle(); + bundle.putString(BundleConstants.KEY_SURVEYOR_STATION_ID, surveyorStationId); + FragmentContainerActivity.start(context, TAG, surveyorStationName, bundle); + } + + public static Fragment newInstance(Bundle args) { + Fragment fragment = new StationSurveyorSeparateFragment(); + fragment.setArguments(args); + return fragment; + } + + @Override + public void deleteCurrentPeriodRecords() { + //删除当前测回记录 + if (currentFragment != null) { + currentFragment.deleteStationOneCycleRecord(0);//0是占位 + } + } + + @Override + public void deleteAllPeriodRecords() { + //删除所有测回记录 + if (currentFragment != null) { + currentFragment.deleteStationAllCycleRecord(); + } + } + + @Override + public void test() { + //数据源 debug使用 + TestDataSelectFragment.show(getChildFragmentManager()); + } + + @Override + public void rollBack() { + //回退 + currentFragment.goBack(); + } + + @Override + public void stationSetting() { + //环境、棱镜设置 + StationSettingsActivity.start(requireContext(), stationId()); +// StationSettingsFragment.start(getContext(), stationId()); + } + //SurveyorSettingsFragment 测量设置 + + @Override + public void adjust() { + //测站平差 + if (currentFragment != null) { + currentFragment.stationAdjust(); + } + } + + @Override + public void startSurveyor() { + stationSettingCheckUtil.checkStationSettings(stationId(), this, this, () -> { + if (currentFragment != null) { + currentFragment.doSurveyor(); + } + }); + } + + private class MyPagerAdapter extends FragmentStatePagerAdapter { + public MyPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public int getCount() { + return fragments.size(); + } + + @Override + public CharSequence getPageTitle(int position) { + return tabs[position]; + } + + @Override + public Fragment getItem(int position) { + return (Fragment) fragments.get(position); + } + + @Override + public int getItemPosition(@NonNull Object object) { + return PagerAdapter.POSITION_NONE; + } + } + + private boolean isHorAnglePage() { + return vp.getCurrentItem() == POSITION_ANGLE_HOR; + } + + private boolean isVerAnglePage() { + return vp.getCurrentItem() == POSITION_ANGLE_VER; + } + + private boolean isDistancePage() { + return vp.getCurrentItem() == POSITION_DISTANCE_MEASURE; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateHorAngleFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateHorAngleFragment.java new file mode 100644 index 0000000..7e951bc --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateHorAngleFragment.java @@ -0,0 +1,475 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.separate; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.LiveData; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; +import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.ViewItemType; +import com.bingce.controlapphelper.util.DigitalUtil; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlapphelper.util.SurveyorCycleUtil; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.fragment.BottomSheetSelectListFragment; +import com.bingce.controlnetwork.fragment.base.BaseFragment; +import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; +import com.bingce.controlnetwork.surveyor.data.CachedData; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateManagerTj; +import com.bingce.controlnetwork.surveyor.state._IsSingleCycleCompletedState; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.ArrayList; + +import blankj.utilcode.util.ToastUtils; + + +/** + * 井定向测量-方位测量 + */ +public class StationSurveyorSeparateHorAngleFragment extends BaseFragment + implements IDistanceTypeChangeListener, ISurveyState, IMeasureOperate { + private StationSurveyorSepatateAdapter adapter = null; + private StateManagerTj stateManager; + private RecyclerView recyclerView; + + private ICachedData cachedData = null; + private ISurveyorData surveyedData = null; + private ISurveyState surveyState; + + private LiveData horCycleLiveData; + private int cycleIndex = 0; + private ArrayList cycleList; + private TextView tvCycle; + private View cycleLayout; + private LiveData cycleLiveData; + + private String stationId() { + if (getArguments() == null) { + return null; + } + return getArguments().getString(KEY_STATION_ID); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate( + R.layout.fragment_station_surveyor_separate_hor_angle, + container, + false); + String stationId = stationId(); + cycleLayout = view.findViewById(R.id.cycleLayout); + tvCycle = view.findViewById(R.id.tvCycle); + recyclerView = view.findViewById(R.id.recyclerView); + + //选择测回 + cycleLayout.setOnClickListener(v -> selectCycleDialog()); + + if (stationId != null) { + //收集信息 + collectData(stationId, + getContext(), + getChildFragmentManager(), + getViewLifecycleOwner(), + this, + (cycleIndex, pointIndex) -> { + if (pointIndex >= 0 && adapter != null && pointIndex < adapter.getItemCount()) { + recyclerView.scrollToPosition(pointIndex); + } + }, + new ICollectCacheCallback() { + @Override + public void onFailure() { + //TODO 收集测站测量信息失败,提示 + } + + @Override + public void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerTj stateManager) { + onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); + surveyState = stateManager; + } + } + ); + } + + return view; + } + + @WorkerThread + private void onCollectStationData( + boolean showSlopDistance, + ICachedData cachedData, + SurveyorData surveyorData, + StateManagerTj stateManager) { + this.stateManager = stateManager; + this.cachedData = cachedData; + surveyedData = surveyorData; + + //测量数据收集完毕后,就可以更新UI了 + runOnUI(() -> { + if (getView() == null) { + return; + } + //刷新UI + if (adapter == null) { + adapter = new StationSurveyorSepatateAdapter(stateManager.getProjectType(), stationId(), + cachedData, stateManager.getTolreanceRecord(), surveyorData, surveyorData, ViewItemType.sepatateHorAngle); + adapter.onShowSlopDistance(showSlopDistance); + if (recyclerView != null) { + recyclerView.setAdapter(adapter); + //滚动到当前目标点 + int currentItemIndex = surveyorData.currentIndex(); + if (currentItemIndex >= 0 && currentItemIndex < adapter.getItemCount()) { + recyclerView.scrollToPosition(currentItemIndex); + } + } + } + + if (getView() != null) { + initCycleObserver(stateManager.getStationRecord()); + + //监听测站数据 + //监听「平距」「斜距」切换,更新UI显示 + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getLiveDataRecord(stationId()) + .observe(getViewLifecycleOwner(), + surveyorStationRecord -> onShowSlopDistance(surveyorStationRecord.isShowSlopDistance())); + } + }); + } + + /** + * 收集测站信息 + */ + private void collectData( + String stationId, + Context context, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner runner, + ISurveyorDataScrollDelegate scrollDelegate, + ICollectCacheCallback callback) { + if (callback == null) { + return; + } + ThreadPoolUtil.execute(() -> { + //读取当前测站的当前测回--很重要 + SurveyorScheduleRecord scheduleRecord = + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .findScheduleSync(SurveyorScheduleConstants.stationCurrentCycleKey(stationId, StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR)); + int defaultCycle = scheduleRecord == null ? 0 : + DigitalUtil.string2Int(scheduleRecord.getStatue(), 0); + //加载测站信息 + SurveyorStationRecord surveyorStationRecord = + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + + //加载对应项目 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(surveyorStationRecord.getProjectId()); + if (projectRecord == null) { + callback.onFailure(); + return; + } + //加载对应限差 + ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + if (toleranceRecord == null) { + callback.onFailure(); + return; + } + + int cycleCount = StationUtilPla.getCycleCount(getMeasureWhat(), surveyorStationRecord, toleranceRecord); + cycleList = SurveyorCycleUtil.cycleStrings(cycleCount, + surveyorStationRecord.leftAndRightSurveyor); + + //创建缓存数据 + CachedData cachedData = + CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR, CachedDataPointType.ALL_POINT, surveyorStationRecord.isAutoClose(), + surveyorStationRecord.isLeftAndRightSurveyor(), + stationId, toleranceRecord); + if (cachedData == null) { + callback.onFailure(); + return; + } + + //是否显示斜距? + cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); + if (cachedData.pointCount() <= 0) { + callback.onFailure(); + return; + } + + //创建stateManager实例 + SurveyorData surveyorDataSource = new SurveyorData(toleranceRecord.getSurveyorCount()); + surveyorDataSource.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); + + StateManagerTj stateManager = StateManagerTj.newInstance( + StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR, + surveyorStationRecord, + context, + fragmentManager, + lifecycleOwner, + toleranceRecord, + cachedData, + surveyorDataSource, + surveyorDataSource, + cachedData, + scrollDelegate, + runner); + //fragment创建后立即计算当前cycle的测量状态 + runner.runOnUI(() -> stateManager.calScheduleWhenEnterSurveyFragment(defaultCycle)); + callback.onSuccess(surveyorStationRecord.isShowSlopDistance(), cachedData, surveyorDataSource, stateManager); + }); + } + + @Override + public void onPause() { + super.onPause(); + } + + public interface ICollectCacheCallback { + void onFailure(); + + void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerTj stateManager); + } + + @Override + public void doSurveyor() { + if (stateManager == null) { + return; + } + stateManager.doSurveyor(); + } + + @Override + public void autoSurvey() { + if (stateManager == null) { + return; + } + stateManager.doAutoSurveyor(); + } + + @Override + public void switchCycle(int cycleIndex) { + if (stateManager == null) { + return; + } + stateManager.switch2Cycle(cycleIndex); + } + + @Override + public void deleteStationAllCycleRecord() { + if (stateManager == null) { + return; + } + stateManager.deleteCurrentStationSurveyorData(); + } + + @Override + public void deleteStationOneCycleRecord(int cycleIndexNoUse) { + if (stateManager == null) { + return; + } + stateManager.deleteCurrentStationSurveyorData(cycleIndex); + } + + @Override + public String stationCheck() { + if (stateManager == null) { + return null; + } + stateManager.stationCheck(); + + return null; + } + + @Override + public void stationAdjust() { + StationUtilPla.checkStationCanAdjust(stationId(), getMeasureWhat(), isCanAdjust -> { + if (!isCanAdjust) { + ToastUtils.showShort("测站未通过检测"); + return; + } + if (stateManager != null) { + stateManager.stationAdjust(); + } + }); + } + + @Override + public void goBack() { + if (stateManager == null) { + return; + } + stateManager.moveBack(); + } + + @Override + public boolean isCurrentCycleComplete() { + if (stateManager == null) + return false; + boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( + stationId(), + stateManager.getCurrentCycle(), + stateManager.getCachedData()); + return completed; + } + + @Override + public int measureTypePosition() { + return 0; + } + + @Override + public int getMeasureWhat() { + return StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR; + } + + @Override + public void onResumeState() { + if (stateManager != null) { + stateManager.resume(); + } + } + + @Override + public void onPauseState() { + if (stateManager != null) { + stateManager.quite(); + } + } + + @Override + public void onShowSlopDistance(boolean value) { + if (cachedData != null) { + cachedData.onShowSlopDistance(value); + } + if (surveyedData != null) { + surveyedData.onShowSlopDistance(value); + } + if (adapter != null) { + adapter.onShowSlopDistance(value); + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + } + } + + @Override + public boolean isSurveying() { + if (surveyState != null) { + return surveyState.isSurveying(); + } + return false; + } + + @Override + public boolean isAutoSurveying() { + if (surveyState != null) { + return surveyState.isAutoSurveying(); + } + return false; + } + + private static final String KEY_STATION_ID = "__station_id"; + + public static final String TAG = StationSurveyorSeparateHorAngleFragment.class.getName(); + + public static StationSurveyorSeparateHorAngleFragment newInstance(String stationId) { + StationSurveyorSeparateHorAngleFragment fragment = new StationSurveyorSeparateHorAngleFragment(); + Bundle bundle = new Bundle(); + bundle.putString(KEY_STATION_ID, stationId); + fragment.setArguments(bundle); + return fragment; + } + + + private void initCycleObserver(SurveyorStationRecord record) { + if (cycleLiveData != null) { + cycleLiveData.removeObservers(this); + } + cycleLiveData = getScheduleLiveData(getHorCycleKey()); + cycleLiveData + .observe(getViewLifecycleOwner(), surveyorScheduleRecord -> refreshCurrentCycleUi(record, surveyorScheduleRecord)); + } + + private void selectCycleDialog() { + if (cycleList == null || cycleList.isEmpty()) { + return; + } + BottomSheetSelectListFragment.showSelect( + getChildFragmentManager(), + getViewLifecycleOwner(), + cycleIndex, + cycleList, + null,//不再限制测期 + (index, string) -> { + switchCycle(index); + }); + } + + + private void refreshCurrentCycleUi(SurveyorStationRecord stationRecord, SurveyorScheduleRecord record) { + //测回发生变化的时候,更新相应ui + int cycleIndex = DigitalUtil.string2Int(record == null ? "0" : record.getStatue(), 0); + //更新测回名称 + if (tvCycle != null) { + boolean showLeftOrRight = true; + if (stationRecord != null) { + showLeftOrRight = stationRecord.leftAndRightSurveyor; + } + tvCycle.setText(SurveyorCycleUtil.cycleName(cycleIndex, showLeftOrRight)); + } + this.cycleIndex = cycleIndex; + } + + protected LiveData getScheduleLiveData(String key) { + return SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .findSchedule(key); + } + + private String getHorCycleKey() { + return SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR); + } +} + + + diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateVerAngleFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateVerAngleFragment.java new file mode 100644 index 0000000..3db9096 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSeparateVerAngleFragment.java @@ -0,0 +1,469 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.separate; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.ViewItemType; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.fragment.BottomSheetSelectListFragment; +import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; +import com.bingce.controlnetwork.fragment.stationsurvey.base.BaseFragmentLazy; +import com.bingce.controlnetwork.surveyor.data.CachedData; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.separateVerAngle.StateManagerSeparateVerAngle; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.ArrayList; + + +import com.bingce.controlnetwork.surveyor.state.separateVerAngle.VerAngleCheckTolerance; +import com.bingce.controlnetwork.surveyor.state.separateVerAngle.VerAngleFindIndexUtil; + +/** + * 分开观测-垂直角 + */ +public class StationSurveyorSeparateVerAngleFragment extends BaseFragmentLazy + implements IDistanceTypeChangeListener, ISurveyState, IMeasureOperate { + private StationSurveyorSepatateAdapter adapter = null; + private StateManagerSeparateVerAngle stateManager; + private RecyclerView recyclerView; + private ICachedData cachedData = null; + private ISurveyorData surveyorData = null; + private ISurveyState surveyState; + + private View llPoint; + private TextView tvPoint; + + private String stationId() { + if (getArguments() == null) { + return null; + } + return getArguments().getString(KEY_STATION_ID); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate( + R.layout.fragment_station_surveyor_separate_ver_angle, + container, + false); + recyclerView = view.findViewById(R.id.recyclerView); + llPoint = view.findViewById(R.id.llPoint); + tvPoint = view.findViewById(R.id.tvPoint); + + llPoint.setOnClickListener(v -> selectSurveyorPoint()); + + return view; + } + + @Override + protected void onFragmentFirstVisible() { + super.onFragmentFirstVisible(); + firstLoadData(); + } + + private void firstLoadData() { + String stationId = stationId(); + if (stationId != null) { + //收集信息 + collectData(stationId, + getContext(), + getChildFragmentManager(), + getViewLifecycleOwner(), + this::runOnUI, + (cycleIndex, pointIndex) -> { + if (cycleIndex >= 0 && adapter != null && cycleIndex < adapter.getItemCount()) { + recyclerView.scrollToPosition(cycleIndex); + } + setTvPointText(); + }, + new ICollectCacheCallback() { + @Override + public void onFailure() { + // TODO: 收集测站测量信息失败,提示 + } + + @Override + public void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerSeparateVerAngle stateManager) { + onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); + surveyState = stateManager; + } + } + ); + } + + } + + + @WorkerThread + private void onCollectStationData( + boolean showSlopDistance, + ICachedData cachedData, + SurveyorData surveyorData, + StateManagerSeparateVerAngle stateManager) { + this.stateManager = stateManager; + this.cachedData = cachedData; + this.surveyorData = surveyorData; + + //测量数据收集完毕后,就可以更新UI了 + runOnUI(() -> { + if (getView() == null) { + return; + } + //刷新UI + if (adapter == null) { + adapter = new StationSurveyorSepatateAdapter(stateManager.getProjectType(), stationId(), + cachedData, stateManager.getTolreanceRecord(), surveyorData, surveyorData, ViewItemType.sepatateVerAngle); + adapter.onShowSlopDistance(showSlopDistance); + if (recyclerView != null) { + recyclerView.setAdapter(adapter); + //滚动到当前目标点 + int currentItemIndex = surveyorData.currentCycleIndex(); + if (currentItemIndex >= 0 && currentItemIndex < adapter.getItemCount()) { + recyclerView.scrollToPosition(currentItemIndex); + } + } + } + + //设置当前点 + setTvPointText(); + + + //监听测站数据 + //监听「平距」「斜距」切换,更新UI显示 + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getLiveDataRecord(stationId()) + .observe(getViewLifecycleOwner(), + surveyorStationRecord -> onShowSlopDistance(surveyorStationRecord.isShowSlopDistance())); + }); + } + + private void setTvPointText() { + SurveyorData data = (SurveyorData) surveyorData; + tvPoint.setText(stringPoint(cachedData.pointName(0, data.currentIndex()))); + } + + /** + * 收集测站信息 + */ + private void collectData( + String stationId, + Context context, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner runner, + ISurveyorDataScrollDelegate scrollDelegate, + ICollectCacheCallback callback) { + if (callback == null) { + return; + } + ThreadPoolUtil.execute(() -> { + //加载测站信息 + SurveyorStationRecord surveyorStationRecord = + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + //加载对应项目 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(surveyorStationRecord.getProjectId()); + if (projectRecord == null) { + callback.onFailure(); + return; + } + //加载对应限差 + ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + if (toleranceRecord == null) { + callback.onFailure(); + return; + } + //创建缓存数据 + CachedData cachedData = + CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER, CachedDataPointType.ALONE_MEASURE_VER_ANGLE_POINT, surveyorStationRecord.isAutoClose(), + surveyorStationRecord.isLeftAndRightSurveyor(), + stationId, toleranceRecord); + if (cachedData == null) { + callback.onFailure(); + return; + } + + //是否显示斜距? + cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); + if (cachedData.pointCount() <= 0) { + setViewVisiableByCacheDataCount(false); + callback.onFailure(); + return; + } + setViewVisiableByCacheDataCount(true); + + // TODO: 2024/8/30 toleranceRecord.getCycleCount() + VerAngleFindIndexUtil.VerFindTarget verFindTarget = VerAngleFindIndexUtil.findFront(stationId, cachedData, + 0, toleranceRecord.getCycleCount()); + + refreshBtnEnable(verFindTarget.getCycleIndex() != -1); + + //创建stateManager实例 + SurveyorData surveyorDataSource = new SurveyorData(toleranceRecord.getSurveyorCount()); + surveyorDataSource.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); + surveyorDataSource.setCurrentIndex(verFindTarget.getPointIndex()); + surveyorDataSource.changeCycleIndex(verFindTarget.getCycleIndex()); + surveyorDataSource.setLeftOrRight(verFindTarget.getLeftOrRight()); + + StateManagerSeparateVerAngle stateManager = StateManagerSeparateVerAngle.newInstance( + StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER, + surveyorStationRecord, + context, + fragmentManager, + lifecycleOwner, + toleranceRecord, + cachedData, + surveyorDataSource, + surveyorDataSource, + cachedData, + scrollDelegate, + runner); + + callback.onSuccess(surveyorStationRecord.isShowSlopDistance(), cachedData, surveyorDataSource, stateManager); + }); + } + + private void setViewVisiableByCacheDataCount(boolean visiable) { + runOnUI(() -> { + llPoint.setVisibility(visiable ? View.VISIBLE : View.GONE); + }); + } + + /** + * 刷新按钮状态 + * + * @param enable + */ + private void refreshBtnEnable(boolean enable) { + if (enable) { + SurveyStateEvent.postIdle(); + } else { + SurveyStateEvent.postCompleted(); + } + } + + @Override + public void onPause() { + super.onPause(); + } + + public interface ICollectCacheCallback { + void onFailure(); + + void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerSeparateVerAngle stateManager); + } + + @Override + public void doSurveyor() { + if (stateManager == null) { + return; + } + stateManager.doSurveyor(); + } + + @Override + public void autoSurvey() { + if (stateManager == null) { + return; + } +// stateManager.doAutoSurveyor(); + } + + @Override + public void switchCycle(int cycleIndex) { + //暂无使用 + } + + @Override + public void deleteStationAllCycleRecord() { + if (stateManager == null) { + return; + } + stateManager.deletePointAllCycleData(); + } + + @Override + public void deleteStationOneCycleRecord(int cycleIndex) { + if (stateManager == null) { + return; + } + stateManager.deleteCurrentCycleData(); + } + + @Override + public String stationCheck() { + //暂无使用 + return null; + } + + @Override + public void stationAdjust() { + if (stateManager != null) { + stateManager.stationAdjust(); + } + } + + @Override + public void goBack() { + if (stateManager == null) { + return; + } + stateManager.startRollBack(); + } + + @Override + public boolean isCurrentCycleComplete() { + String stationId = stationId(); + if (stationId == null || stateManager == null) { + return true; + } + return VerAngleCheckTolerance.isAllPointMeasured(stationId, cachedData, stateManager.getCycleCount()); + } + + @Override + public int measureTypePosition() { + return 0; + } + + @Override + public int getMeasureWhat() { + return StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER; + } + + @Override + public void onResumeState() { + if (stateManager != null) { + stateManager.resume(); + } + } + + @Override + public void onPauseState() { + if (stateManager != null) { + stateManager.quite(); + } + } + + @Override + public void onShowSlopDistance(boolean value) { + if (cachedData != null) { + cachedData.onShowSlopDistance(value); + } + if (surveyorData != null) { + surveyorData.onShowSlopDistance(value); + } + if (adapter != null) { + adapter.onShowSlopDistance(value); + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + } + } + + @Override + public boolean isSurveying() { + if (surveyState != null) { + return surveyState.isSurveying(); + } + return false; + } + + @Override + public boolean isAutoSurveying() { + if (surveyState != null) { + return surveyState.isAutoSurveying(); + } + return false; + } + + private static final String KEY_STATION_ID = "__station_id"; + + public static final String TAG = StationSurveyorSeparateVerAngleFragment.class.getName(); + + public static StationSurveyorSeparateVerAngleFragment newInstance(String stationId) { + StationSurveyorSeparateVerAngleFragment fragment = new StationSurveyorSeparateVerAngleFragment(); + Bundle bundle = new Bundle(); + bundle.putString(KEY_STATION_ID, stationId); + fragment.setArguments(bundle); + return fragment; + } + + private void selectSurveyorPoint() { + if (stateManager == null) { + return; + } + if (surveyorData == null) { + return; + } + if (cachedData == null || cachedData.pointCount() == 0) { + return; + } + + int currentCycle = stateManager.getCurrentCycle(); + + ArrayList showPointList = new ArrayList<>(); + for (int i = 0; i < cachedData.realPointCount(); i++) { + showPointList.add(cachedData.pointName(currentCycle, i)); + } + + BottomSheetSelectListFragment.showSelect( + getChildFragmentManager(), + getViewLifecycleOwner(), + surveyorData.currentIndex(), + showPointList, + null,//不再限制测期 + (index, string) -> { + //切换测点 + VerAngleFindIndexUtil.VerFindTarget target = VerAngleFindIndexUtil.getTargetByPointIndexFront(stateManager.stationId(), cachedData, + index, stateManager.getTolreanceRecord().cycleCount); // TODO: 2024/8/30 getTolreanceRecord().cycleCount + stateManager.setSurveyorData(target, true); + //刷新ui + setTvPointText(); + cachedData.notifyDateChange(); + }); + } + + private String stringPoint(String name) { + return String.format("测点:%s", name); + } + +} + + + diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSepatateAdapter.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSepatateAdapter.java new file mode 100644 index 0000000..04331f8 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/separate/StationSurveyorSepatateAdapter.java @@ -0,0 +1,129 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.separate; + +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.IAdapter; +import com.bingce.controlapphelper.model.ViewItemType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.ui.vh.AbstractSurveyorDataViewHolder; +import com.bingce.controlnetwork.ui.vh.SurveyorDataWellDistanceViewHolder; +import com.bingce.controlnetwork.ui.widget.ViewFactory; + +import java.util.Objects; + +/** + * 测量记录adapter + * 分开观测 水平角,垂直角,距离共用 + */ +public class StationSurveyorSepatateAdapter extends RecyclerView.Adapter + implements IAdapter, IDistanceTypeChangeListener { + + private ICachedData cachedData; + private final ISurveyorData surveyorData; + private final ICycleRecorder cycleRecorder; + private boolean showSlopDistance = true; + private final String projectType; + private final String stationId; + private final ViewItemType layoutType;//区分水平还是距离 + private final ToleranceDetailRecord toleranceRecord;//区分水平还是距离 + + + public StationSurveyorSepatateAdapter( + String projectType, + String stationId, + ICachedData cachedData, + ToleranceDetailRecord toleranceRecord, + ICycleRecorder cycleRecorder, + ISurveyorData surveyorData, + ViewItemType layoutType) { + this.projectType = projectType; + this.stationId = stationId; + this.cachedData = cachedData; + this.toleranceRecord = toleranceRecord; + this.surveyorData = surveyorData; + this.cycleRecorder = cycleRecorder; + this.layoutType = layoutType; + //注册数据监听 + cachedData.register(this); + } + + public void setCachedData(ICachedData cachedData) { + this.cachedData.unregister(this); + this.cachedData = cachedData; + //注册数据监听 + cachedData.register(this); + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return Objects.requireNonNull(ViewFactory.generatorViewHolder(parent.getContext(), parent, layoutType)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof SurveyorDataWellDistanceViewHolder) { + SurveyorDataWellDistanceViewHolder holderDistance = (SurveyorDataWellDistanceViewHolder) holder; + holderDistance.setup(position, + projectType, + stationId, + showSlopDistance, + cachedData, + cycleRecorder, + surveyorData); + } else if (holder instanceof AbstractSurveyorDataViewHolder) { + AbstractSurveyorDataViewHolder abstractSurveyorDataViewHolder = (AbstractSurveyorDataViewHolder) holder; + abstractSurveyorDataViewHolder.setup(position, + stationId, + showSlopDistance, + cachedData, + cycleRecorder, + surveyorData); + } + + holder.itemView.setOnClickListener(v -> { + if (iItemClickListener != null) { + iItemClickListener.click(position); + } + }); + } + + @Override + public int getItemCount() { + if (layoutType == ViewItemType.aloneDistanceMeasure) { + return cachedData.realPointCount(); + } else if (layoutType == ViewItemType.sepatateVerAngle) { + return toleranceRecord.cycleCount;// TODO: 2024/8/30 + } else { + return cachedData.pointCount(); + } + } + + @Override + public void onDataChange() { + notifyDataSetChanged(); + } + + @Override + public void onShowSlopDistance(boolean value) { + this.showSlopDistance = value; + } + + + private IItemClickListener iItemClickListener; + + public void setOnItemClickListener(IItemClickListener iItemClickListener) { + this.iItemClickListener = iItemClickListener; + } + + public interface IItemClickListener { + void click(int position); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellDistanceDataFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellDistanceDataFragment.java new file mode 100644 index 0000000..48bad39 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellDistanceDataFragment.java @@ -0,0 +1,500 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.well; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.datasource.database.ProjectTypeValue; +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; +import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.util.DigitalUtil; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.adapter.SurveyorStationRecordsWellAdapter; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; +import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; +import com.bingce.controlnetwork.fragment.stationsurvey.base.BaseFragmentLazy; +import com.bingce.controlnetwork.surveyor.data.CachedData; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.wellDistance.StateManagerWell; +import com.bingce.controlnetwork.surveyor.state.wellDistance._CheckToleranceState; +import com.bingce.utils.ThreadPoolUtil; + +import blankj.utilcode.util.ToastUtils; +import com.bingce.controlnetwork.surveyor.state.wellDistance.IWeatherShowDialogListener; + + +/** + * 井定向钢丝测距或者单独测距 + */ +public class StationSurveyorWellDistanceDataFragment extends BaseFragmentLazy + implements IDistanceTypeChangeListener, ISurveyState, IMeasureOperate { + + private SurveyorStationRecordsWellAdapter adapter = null; + private StateManagerWell stateManager; //这里的stateManager是克隆StateManager + private RecyclerView recyclerView; + private ICachedData cachedData = null; + private ISurveyorData surveyedData = null; + private ISurveyState surveyState; + + private final IWeatherShowDialogListener weatherShowDialogListener = (stationId, currentCycleIndex, pointId, beforeOrAfter, msg) -> { + if (getView() == null) return; + TipsWith2OptionFragment + .tips( + getChildFragmentManager(), + getViewLifecycleOwner(), + Tools.getString(R.string.confirm), + Tools.getString(R.string.cancel), + msg, + new TipsWith2OptionFragment.SimpleCallback() { + @Override + public void onConfirm() { +// DistanceWeatherSettingTjActivity.launch(requireContext(), stationId, currentCycleIndex, pointId, beforeOrAfter); + } + } + ); + }; + + + private String stationId() { + if (getArguments() == null) { + return null; + } + return getArguments().getString(KEY_STATION_ID); + } + + private String getWellType() { + if (getArguments() != null) { + return getArguments().getString(KEY_WELL_TYPE); + } + return null; + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate( + R.layout.fragment_project_surveyor_station_point_list_layout, + container, + false); + recyclerView = view.findViewById(R.id.recycler_view); + + String stationId = stationId(); + if (stationId != null) { + //收集信息 + collectData(stationId, + getContext(), + getChildFragmentManager(), + getViewLifecycleOwner(), + this::runOnUI, + this::scrollToPosition, + new ICollectCacheCallback() { + @Override + public void onFailure() { + + } + + @Override + public void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerWell stateManager) { + onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); + surveyState = stateManager; + } + } + ); + } + + return view; + } + + @Override + public boolean getUserVisibleHint() { + return super.getUserVisibleHint(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + } + + @WorkerThread + private void onCollectStationData( + boolean showSlopDistance, + ICachedData cachedData, + SurveyorData surveyorData, + StateManagerWell stateManager) { + + this.stateManager = stateManager; + this.cachedData = cachedData; + this.surveyedData = surveyorData; + + //更新完棱镜类型刷新页面 +// stateManager.setRefreshFragmentUiListener(() -> changeCacheDataAndRefreshUi(stationId())); + + //测量数据收集完毕后,就可以更新UI了 + runOnUI(() -> { + if (getView() == null) { + return; + } + + //刷新UI + if (adapter == null) { + adapter = new SurveyorStationRecordsWellAdapter(stateManager.getProjectType(), stationId(), + cachedData, surveyorData, surveyorData, getWellType()); + adapter.onShowSlopDistance(showSlopDistance); + if (recyclerView != null) { + recyclerView.setAdapter(adapter); + //滚动到当前目标点 + int currentItemIndex = surveyorData.currentIndex(); + scrollToPosition(0, currentItemIndex); + } + + adapter.setOnItemClickListener(position -> { + if (isSurveying()) { + ToastUtils.showShort("正在测量中,请稍后..."); + return; + } + stateManager.setCurrentIndex(position); + stateManager.setCurrentCycleIndex(0); + stateManager.refeshRollBackBtn(); + + scrollToPosition(0, position); + }); + + } + + //监听测站数据,更新界面「平距」「斜距」显示 + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getLiveDataRecord(stationId()) + .observe(getViewLifecycleOwner(), + surveyorStationRecord -> onShowSlopDistance(surveyorStationRecord.isShowSlopDistance())); + }); + } + + private void scrollToPosition(int cycleIndex, int position) { + if (position >= 0 && adapter != null && position < adapter.getItemCount()) { + runOnUI(() -> { + recyclerView.scrollToPosition(position); + adapter.notifyDataSetChanged(); + }); + } + } + + /** + * 收集测站信息 + */ + private void collectData( + String stationId, + Context context, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner runner, + ISurveyorDataScrollDelegate scrollDelegate, + ICollectCacheCallback callback) { + if (callback == null) { + return; + } + ThreadPoolUtil.execute(() -> { + //读取当前测站的当前测回--很重要 + SurveyorScheduleRecord scheduleRecord = + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .findScheduleSync(SurveyorScheduleConstants.stationCurrentCycleKey(stationId, StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE)); + int defaultCycle = scheduleRecord == null ? 0 : + DigitalUtil.string2Int(scheduleRecord.getStatue(), 0); + //加载测站信息 + SurveyorStationRecord surveyorStationRecord = + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + //加载对应项目 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(surveyorStationRecord.getProjectId()); + if (projectRecord == null) { + callback.onFailure(); + return; + } + //加载对应限差 + ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + if (toleranceRecord == null) { + callback.onFailure(); + return; + } + //创建缓存数据 + CachedDataPointType cachedDataPointType = CachedDataPointType.ALONE_MEASURE_DISTANCE_POINT; + if (isConnection(surveyorStationRecord.projectType)) { + cachedDataPointType = CachedDataPointType.STEEL_POINT; + } + CachedData cachedData = CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, cachedDataPointType, surveyorStationRecord.isAutoClose(), + surveyorStationRecord.isLeftAndRightSurveyor(), + stationId, toleranceRecord); + if (cachedData == null) { + callback.onFailure(); + return; + } + + //是否显示斜距? + cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); + + //创建stateManager实例 + SurveyorData surveyorDataSource = new SurveyorData(ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT); + surveyorDataSource.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); + + StateManagerWell stateManager = StateManagerWell.newInstance( + surveyorStationRecord, + context, + fragmentManager, + lifecycleOwner, + toleranceRecord, + cachedData, + surveyorDataSource, + surveyorDataSource, + cachedData, + scrollDelegate, + runner, + weatherShowDialogListener + ); + + callback.onSuccess(surveyorStationRecord.isShowSlopDistance(), cachedData, surveyorDataSource, stateManager); + }); + } + + /** + * 改变cacheData并刷新Ui + */ + private void changeCacheDataAndRefreshUi(String stationId) { + ThreadPoolUtil.execute(() -> { + //加载测站信息 + SurveyorStationRecord surveyorStationRecord = + SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + //加载对应项目 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(surveyorStationRecord.getProjectId()); + if (projectRecord == null) { + return; + } + //加载对应限差 + ToleranceDetailRecord toleranceRecord = SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + if (toleranceRecord == null) { + return; + } + //创建缓存数据 + CachedDataPointType cachedDataPointType = CachedDataPointType.ALONE_MEASURE_DISTANCE_POINT; + if (isConnection(surveyorStationRecord.projectType)) { + cachedDataPointType = CachedDataPointType.STEEL_POINT; + } + CachedData cachedData = CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, cachedDataPointType, surveyorStationRecord.isAutoClose(), + surveyorStationRecord.isLeftAndRightSurveyor(), + stationId, toleranceRecord); + if (cachedData != null) { + //是否显示斜距? + cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); +// stateManager.setCachedData(cachedData); + adapter.setCachedData(cachedData); + runOnUI(() -> adapter.notifyDataSetChanged()); + } + }); + } + + public interface ICollectCacheCallback { + void onFailure(); + + void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerWell stateManager); + } + + @Override + public void doSurveyor() { + if (stateManager == null) { + return; + } + stateManager.doSurveyor(); + } + + @Override + public void autoSurvey() { + + + } + + @Override + public void switchCycle(int cycleIndex) { + if (stateManager == null) { + return; + } + stateManager.switch2Cycle(cycleIndex); + } + + @Override + public void deleteStationAllCycleRecord() { + if (stateManager == null) { + return; + } + stateManager.deletePointAllCycleData(); + } + + @Override + public void deleteStationOneCycleRecord(int cycleIndex) { + if (stateManager == null) { + return; + } + stateManager.deletePointCurrentCycleData(); + } + + @Override + public String stationCheck() { + if (stateManager == null) { + return null; + } + stateManager.stationCheck(); + return null; + } + + @Override + public void stationAdjust() { + if (stateManager != null) { + stateManager.stationAdjust(); + } + } + + @Override + public void goBack() { + if (stateManager == null) { + return; + } + stateManager.moveBack(); + } + + @Override + public void onShowSlopDistance(boolean value) { + if (cachedData != null) { + cachedData.onShowSlopDistance(value); + } + if (surveyedData != null) { + surveyedData.onShowSlopDistance(value); + } + if (adapter != null) { + adapter.onShowSlopDistance(value); + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + } + } + + @Override + public boolean isSurveying() { + if (surveyState != null) { + return surveyState.isSurveying(); + } + return false; + } + + @Override + public boolean isAutoSurveying() { + if (surveyState != null) { + return surveyState.isAutoSurveying(); + } + return false; + } + + private static final String KEY_STATION_ID = "__station_id"; + private static final String KEY_WELL_TYPE = "__well_type"; + public static final String TAG = StationSurveyorWellDistanceDataFragment.class.getName(); + + public static StationSurveyorWellDistanceDataFragment newInstance(String stationId, String wellType) { + StationSurveyorWellDistanceDataFragment fragment = new StationSurveyorWellDistanceDataFragment(); + Bundle bundle = new Bundle(); + bundle.putString(KEY_STATION_ID, stationId); + bundle.putString(KEY_WELL_TYPE, wellType); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public boolean isCurrentCycleComplete() { + if (stateManager == null) + return false; + return _CheckToleranceState.isCompleteAllPointForAloneDistance(stationId(), 0, stateManager.getCachedData()); + } + + @Override + public int measureTypePosition() { + return 0; + } + + @Override + public int getMeasureWhat() { + return StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE; + } + + @Override + public void onResumeState() { + if (stateManager != null) { + stateManager.resume(); + } + } + + @Override + public void onPauseState() { + if (stateManager != null) { + stateManager.quite(); + } + } + + @Override + protected void onFragmentFirstVisible() { + if (stateManager != null) + stateManager.calScheduleWhenEnterSurveyFragment(); + } + + /** + * 是否联系测量 + * + * @param projectType 项目类型 + * @return + */ + private boolean isConnection(String projectType) { + return ProjectTypeValue.CONNECTION.equals(projectType); + } + +} + + + diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellFragment.java new file mode 100644 index 0000000..9504c0e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellFragment.java @@ -0,0 +1,457 @@ +package com.bingce.controlnetwork.fragment.stationsurvey.well; + + +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.BundleConstants; +import com.bingce.controlapphelper.util.DigitalUtil; +import com.bingce.controlapphelper.util.SurveyorCycleUtil; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.activity.fragmentcontainer.FragmentContainerActivity; +import com.bingce.controlnetwork.adapter.SurveyorStationRecordsWellAdapter; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.event.RefreshRollBackEvent; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.fragment.BottomSheetSelectListFragment; +import com.bingce.controlnetwork.fragment.base.BaseFragment; +import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; +import com.bingce.controlnetwork.newui.stationsetting.StationSettingsActivity; +import com.bingce.controlnetwork.newui.stationsurveyor.ISurveyorMenuOperate; +import com.bingce.controlnetwork.newui.stationsurveyor.StationSurveyorHomeActivity; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.surveyor.TestDataSelectFragment; +import com.bingce.controlnetwork.util.StationSettingCheckUtil; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.utils.ThreadPoolUtil; +import com.flyco.tablayout.SlidingTabLayout; +import com.github.razir.progressbutton.DrawableButtonExtensionsKt; +import com.github.razir.progressbutton.ProgressButtonHolderKt; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; + +/** + * 测站测量页面(开始测量) + */ +public class StationSurveyorWellFragment extends BaseFragment implements ISurveyorMenuOperate { + public static final String TAG = StationSurveyorWellFragment.class.getName(); + + private MenuItem menuItemRollBack; + + private SurveyorStationRecord surveyorStationRecord; + private int cycleIndex = 0; + + //方位观测fragment的在adapter的索引 + public static final int POSITION_DIRECTION_MEASURE = 0; + public static final int POSITION_DISTANCE_MEASURE = 1; + private final String[] tabs = { + "方位观测", "单独测距" + }; + + private List fragments; + private IMeasureOperate currentFragment; + + private ViewPager vp; + + private final StationSettingCheckUtil stationSettingCheckUtil = new StationSettingCheckUtil(); + + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onRefreshGoBack(RefreshRollBackEvent event) { + if (vp != null) { + int currentItem = vp.getCurrentItem(); + if (currentItem == POSITION_DIRECTION_MEASURE) { + setRollBackEnable(event.validate); + } else if (currentItem == POSITION_DISTANCE_MEASURE) { + setRollBackEnable(event.validate); + } + } + } + + private void setRollBackEnable(boolean validate) { + FragmentActivity activity = getActivity(); + if (activity != null) { + StationSurveyorHomeActivity homeActivity = (StationSurveyorHomeActivity) activity; + homeActivity.setRollBackEnable(validate); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSurveyorStateChanged(SurveyStateEvent event) { + if (getView() == null) { + return; + } + Button surveyorButton = getView().findViewById(R.id.surveyor); + if (surveyorButton == null) { + return; + } + if (event.isIdle() || event.isSuccess() || event.isCompleted()) { + DrawableButtonExtensionsKt.hideProgress(surveyorButton, R.string.start_surveyor); + } else if (event.isSurveying()) { + DrawableButtonExtensionsKt.showProgress(surveyorButton, progressParams -> { + progressParams.setButtonTextRes(R.string.tips_surveying); + progressParams.setProgressColor(Color.WHITE); + return null; + }); + } else if (event.isFailure()) { + DrawableButtonExtensionsKt.hideProgress(surveyorButton, R.string.tips_surveyor_failure_and_retry); + } + + boolean enable = event.isIdle() || event.isFailure() || event.isSuccess(); + + setSurveyorEnable(getView(), R.id.surveyor, enable); + } + + private String stationId() { + if (getArguments() == null) { + return null; + } + return getArguments().getString(BundleConstants.KEY_SURVEYOR_STATION_ID); + } + + @Override + public void onStart() { + super.onStart(); + EventBus.getDefault().register(this); + } + + @Override + public void onStop() { + super.onStop(); + EventBus.getDefault().unregister(this); + } + + @Override + public void onResume() { + super.onResume(); + //测量界面保持常亮 + if (getActivity() != null) { + getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + if (currentFragment != null) { + currentFragment.onResumeState(); + } + } + + @Override + public void onPause() { + super.onPause(); + //清除界面常亮 + if (getActivity() != null) { + getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + if (currentFragment != null) { + currentFragment.onPauseState(); + } + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_project_surveyor_station_detail_layout_well, + container, + false); + + //2.设置测量按钮 + Button surveyor = view.findViewById(R.id.surveyor); + if (surveyor != null) { + ProgressButtonHolderKt.bindProgressButton(getViewLifecycleOwner(), surveyor); + } + setSurveyorClick(view, R.id.surveyor, this::startSurveyor); + + //3.查询测站信息 + ThreadPoolUtil.execute(() -> { + surveyorStationRecord = SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId()); + //监听当前测回切换 + monitorCurrentCycle(view); + //监听数据变化 + ToleranceDetailRecord toleranceRecord = getTolerance(surveyorStationRecord); + if (toleranceRecord == null) { + return; + } + //注册UI监听 + View pick = view.findViewById(R.id.cycleLayout); + if (pick == null) { + return; + } + + int cycleCount = StationUtilPla.getCycleCount(StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE, surveyorStationRecord, toleranceRecord); + + pick.setOnClickListener(v -> { + //测回的点击事件 + + ArrayList cycleList = SurveyorCycleUtil.cycleStrings(cycleCount, + surveyorStationRecord != null && surveyorStationRecord.leftAndRightSurveyor); + + TextView circleText = view.findViewById(R.id.circle_text); + runOnUI(() -> BottomSheetSelectListFragment.showSelect( + getChildFragmentManager(), + getViewLifecycleOwner(), + cycleIndex, + cycleList, + null,//不再限制测期 + (index, string) -> { + if (circleText != null) { + circleText.setText(string); + } + cycleIndex = index; + if (currentFragment != null) { + //检测当前测回是否完成 + currentFragment.switchCycle(cycleIndex); + } + })); + }); + }); + + setHasOptionsMenu(true); + + return view; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initViewPager(view); + } + + private void initViewPager(View view) { + fragments = new ArrayList<>(); + StationSurveyorWellLevelAngleDataFragment fragmentAngle = StationSurveyorWellLevelAngleDataFragment.newInstance(stationId(), SurveyorStationRecordsWellAdapter.TYPE_HORIZONTAL_ANGLE); + fragments.add(fragmentAngle); + StationSurveyorWellDistanceDataFragment fragmentDistance = StationSurveyorWellDistanceDataFragment.newInstance(stationId(), SurveyorStationRecordsWellAdapter.TYPE_DISTANCE); + fragments.add(fragmentDistance); + + SlidingTabLayout tabLayout = view.findViewById(R.id.tabLayout); + vp = view.findViewById(R.id.vp); + vp.setAdapter(new MyPagerAdapter(getChildFragmentManager())); + tabLayout.setViewPager(vp); + + vp.setCurrentItem(POSITION_DIRECTION_MEASURE); + currentFragment = fragments.get(POSITION_DIRECTION_MEASURE); + + vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + currentFragment = fragments.get(position); + View pick = view.findViewById(R.id.cycleLayout); + //钢丝测距不显示选择测回 + pick.setVisibility(position == POSITION_DIRECTION_MEASURE ? View.VISIBLE : View.GONE); + //刷新按钮状态 + boolean currentCycleComplete = currentFragment.isCurrentCycleComplete(); + if (currentCycleComplete) { + SurveyStateEvent.postCompleted(); + } else { + SurveyStateEvent.postIdle(); + } + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + + } + + @WorkerThread + private void monitorCurrentCycle(View view) { + if (getActivity() != null) { + getActivity().runOnUiThread(() -> SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .findSchedule(getScheduleId()) + .observe(getViewLifecycleOwner(), record -> { + TextView circleText = view.findViewById(R.id.circle_text); + //测回发生变化的时候,更新相应ui + int cycleIndex = DigitalUtil.string2Int(record == null ? "0" : record.getStatue(), 0); + //更新测回名称 + if (circleText != null) { + boolean showLeftOrRight = true; + if (surveyorStationRecord != null) { + showLeftOrRight = surveyorStationRecord.leftAndRightSurveyor; + } + circleText.setText(SurveyorCycleUtil.cycleName(cycleIndex, showLeftOrRight)); + } + StationSurveyorWellFragment.this.cycleIndex = cycleIndex; + })); + } + } + + private String getScheduleId() { + int currentItem = vp.getCurrentItem(); + String scheduleId; + if (currentItem == POSITION_DIRECTION_MEASURE) { + scheduleId = SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT); + } else { + scheduleId = SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE); + } + return scheduleId; + } + + private static void setSurveyorClick(View rootView, int id, Runnable runnable) { + View view = rootView.findViewById(id); + if (view != null) { + view.setOnClickListener(v -> runnable.run()); + } + } + + private static void setSurveyorEnable(View rootView, int id, boolean enable) { + if (rootView == null) { + return; + } + View view = rootView.findViewById(id); + if (view != null) { + view.setEnabled(enable); + if (enable) { + view.setAlpha(1); + } else { + view.setAlpha(.4f); + } + } + } + + @WorkerThread + private static ToleranceDetailRecord getTolerance(SurveyorStationRecord surveyorStationRecord) { + if (surveyorStationRecord == null) { + return null; + } + //获取project信息 + ProjectRecord projectRecord = SurveyorDatabaseFactory + .instance + .getProjectDataSource() + .getRecord(surveyorStationRecord.getProjectId()); + if (projectRecord == null) { + return null; + } + //获取限差数据 + return SurveyorDatabaseFactory + .instance + .getToleranceDetailDataSource() + .getRecordSync(projectRecord.getToleranceId()); + } + + public static void start(Context context, String surveyorStationId, String surveyorStationName) { + Bundle bundle = new Bundle(); + bundle.putString(BundleConstants.KEY_SURVEYOR_STATION_ID, surveyorStationId); + FragmentContainerActivity.start(context, TAG, surveyorStationName, bundle); + } + + public static Fragment newInstance(Bundle args) { + Fragment fragment = new StationSurveyorWellFragment(); + fragment.setArguments(args); + return fragment; + } + + @Override + public void deleteCurrentPeriodRecords() { + //删除当前测回记录 + if (surveyorStationRecord != null && currentFragment != null) { + //通知fragment + currentFragment.deleteStationOneCycleRecord(cycleIndex); + } + } + + @Override + public void deleteAllPeriodRecords() { + //删除所有测回记录 + if (surveyorStationRecord != null && currentFragment != null) { + //通知fragment + currentFragment.deleteStationAllCycleRecord(); + } + } + + @Override + public void test() { + //数据源 debug使用 + TestDataSelectFragment.show(getChildFragmentManager()); + } + + @Override + public void rollBack() { + //回退 + currentFragment.goBack(); + } + + @Override + public void stationSetting() { + //环境、棱镜设置 + StationSettingsActivity.start(requireContext(), stationId()); +// StationSettingsFragment.start(getContext(), stationId()); + } + //SurveyorSettingsFragment 测量设置 + + @Override + public void adjust() { + //测站平差,平差检测 + if (currentFragment != null) { + currentFragment.stationAdjust(); + } + } + + @Override + public void startSurveyor() { + stationSettingCheckUtil.checkStationSettings(stationId(), this, this, () -> { + if (currentFragment != null) { + currentFragment.doSurveyor(); + } + }); + } + + private class MyPagerAdapter extends FragmentPagerAdapter { + public MyPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public int getCount() { + return fragments.size(); + } + + @Override + public CharSequence getPageTitle(int position) { + return tabs[position]; + } + + @Override + public Fragment getItem(int position) { + return (Fragment) fragments.get(position); + } + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDefaultFragment.java b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellLevelAngleDataFragment.java similarity index 70% rename from app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDefaultFragment.java rename to app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellLevelAngleDataFragment.java index d381b58..df82a5e 100644 --- a/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/angledistance/MeasureDefaultFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/fragment/stationsurvey/well/StationSurveyorWellLevelAngleDataFragment.java @@ -1,4 +1,4 @@ -package com.bingce.controlnetwork.fragment.stationsurvey.angledistance; +package com.bingce.controlnetwork.fragment.stationsurvey.well; import android.content.Context; import android.os.Bundle; @@ -11,7 +11,6 @@ import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; import androidx.fragment.app.FragmentManager; import androidx.lifecycle.LifecycleOwner; -import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; @@ -19,48 +18,36 @@ import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.RefreshGoBackButton; -import com.bingce.controlapphelper.surveyor.data.CachedData; -import com.bingce.controlapphelper.surveyor.data.IDistanceTypeChangeListener; -import com.bingce.controlapphelper.surveyor.data.SurveyorData; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParamAuto; import com.bingce.controlapphelper.util.DigitalUtil; import com.bingce.controlapphelper.util.IUIRunner; -import com.bingce.controlnetwork.adapter.MeasureAngleDistanceAdapter; -import com.bingce.controlnetwork.fragment.ComponentStationSurveyorDataListFragment; -import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; -import com.bingce.controlnetwork.fragment.base.BaseFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.controlnetwork.surveyor.state.angledistance.StateManager; -import com.bingce.controlnetwork.surveyor.state.angledistance._IsSingleCycleCompletedState; -import com.bingce.totalstation.TotalStation; -import com.bingce.utils.ThreadPoolUtil; - -import org.greenrobot.eventbus.EventBus; - import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.adapter.MeasureAngleDistanceAdapter; -import com.bingce.controlnetwork.fragment.ComponentStationSurveyorDataListFragment; -import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; +import com.bingce.controlnetwork.adapter.SurveyorStationRecordsWellAdapter; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; import com.bingce.controlnetwork.fragment.base.BaseFragment; import com.bingce.controlnetwork.fragment.stationsurvey.IMeasureOperate; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.controlnetwork.surveyor.state.angledistance.StateManager; -import com.bingce.controlnetwork.surveyor.state.angledistance._IsSingleCycleCompletedState; +import com.bingce.controlnetwork.surveyor.data.CachedData; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.IDistanceTypeChangeListener; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateManagerTj; +import com.bingce.controlnetwork.surveyor.state._IsSingleCycleCompletedState; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.utils.ThreadPoolUtil; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; +import blankj.utilcode.util.ToastUtils; /** - * 测角测距 + * 井定向测量-方位测量 */ -public class MeasureDefaultFragment extends BaseFragment +public class StationSurveyorWellLevelAngleDataFragment extends BaseFragment implements IDistanceTypeChangeListener, ISurveyState, IMeasureOperate { - private MeasureAngleDistanceAdapter adapter = null; - private StateManager stateManager; + private SurveyorStationRecordsWellAdapter adapter = null; + private StateManagerTj stateManager; private RecyclerView recyclerView; private ICachedData cachedData = null; private ISurveyorData surveyedData = null; @@ -73,9 +60,9 @@ public class MeasureDefaultFragment extends BaseFragment return getArguments().getString(KEY_STATION_ID); } - private String getTypeAngleOrDistance() { + private String getWellType() { if (getArguments() != null) { - return getArguments().getString(KEY_TYPE_ANGLE_OR_DISTANCE); + return getArguments().getString(KEY_WELL_TYPE); } return null; } @@ -98,7 +85,7 @@ public class MeasureDefaultFragment extends BaseFragment getChildFragmentManager(), getViewLifecycleOwner(), this::runOnUI, - index -> { + (cycleIndex, index) -> { if (index >= 0 && adapter != null && index < adapter.getItemCount()) { recyclerView.scrollToPosition(index); } @@ -106,10 +93,11 @@ public class MeasureDefaultFragment extends BaseFragment new ICollectCacheCallback() { @Override public void onFailure() { + //TODO 收集测站测量信息失败,提示 } @Override - public void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManager stateManager) { + public void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerTj stateManager) { onCollectStationData(showSlopDistance, cachedData, surveyorData, stateManager); surveyState = stateManager; } @@ -125,17 +113,21 @@ public class MeasureDefaultFragment extends BaseFragment boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, - StateManager stateManager) { + StateManagerTj stateManager) { this.stateManager = stateManager; this.cachedData = cachedData; surveyedData = surveyorData; //测量数据收集完毕后,就可以更新UI了 runOnUI(() -> { + if (getView() == null) { + return; + } + //刷新UI if (adapter == null) { - adapter = new MeasureAngleDistanceAdapter(stationId(), - cachedData, surveyorData, surveyorData, getTypeAngleOrDistance()); + adapter = new SurveyorStationRecordsWellAdapter(stateManager.getProjectType(), stationId(), + cachedData, surveyorData, surveyorData, getWellType()); adapter.onShowSlopDistance(showSlopDistance); if (recyclerView != null) { recyclerView.setAdapter(adapter); @@ -167,21 +159,20 @@ public class MeasureDefaultFragment extends BaseFragment FragmentManager fragmentManager, LifecycleOwner lifecycleOwner, IUIRunner runner, - IScrollDelegate scrollDelegate, + ISurveyorDataScrollDelegate scrollDelegate, ICollectCacheCallback callback) { if (callback == null) { return; } - boolean isSupportAutoMode = TotalStation.getInstance().isSupportMotor(); ThreadPoolUtil.execute(() -> { //读取当前测站的当前测回--很重要 SurveyorScheduleRecord scheduleRecord = SurveyorDatabaseFactory .instance .getScheduleDataSource() - .findScheduleSync(SurveyorScheduleConstants.getCurrentCycleKey(stationId, SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE)); + .findScheduleSync(SurveyorScheduleConstants.stationCurrentCycleKey(stationId, StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT)); int defaultCycle = scheduleRecord == null ? 0 : - DigitalUtil.valueOfIntString(scheduleRecord.getStatue(), 0); + DigitalUtil.string2Int(scheduleRecord.getStatue(), 0); //加载测站信息 SurveyorStationRecord surveyorStationRecord = SurveyorDatabaseFactory @@ -208,7 +199,7 @@ public class MeasureDefaultFragment extends BaseFragment } //创建缓存数据 CachedData cachedData = - CachedData.newInstance(surveyorStationRecord.isAutoClose(), + CachedData.newInstance(StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, CachedDataPointType.ALL_POINT, surveyorStationRecord.isAutoClose(), surveyorStationRecord.isLeftAndRightSurveyor(), stationId, toleranceRecord); if (cachedData == null) { @@ -216,7 +207,6 @@ public class MeasureDefaultFragment extends BaseFragment return; } - //是否显示斜距? cachedData.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); if (cachedData.pointCount() <= 0) { @@ -228,19 +218,14 @@ public class MeasureDefaultFragment extends BaseFragment SurveyorData surveyorDataSource = new SurveyorData(toleranceRecord.getSurveyorCount()); surveyorDataSource.onShowSlopDistance(surveyorStationRecord.isShowSlopDistance()); - //存入cacheData 用于自动测量时使用 - MeasureVm measureVm = new ViewModelProvider(requireParentFragment()).get(MeasureVm.class); - RequestSurveyorParamAuto requestSurveyorParamAuto = new RequestSurveyorParamAuto(stationId, cachedData); - measureVm.setRequestSurveyorParamAuto(requestSurveyorParamAuto); - - StateManager stateManager = StateManager.newInstance( - isSupportAutoMode, - requestSurveyorParamAuto, + StateManagerTj stateManager = StateManagerTj.newInstance( + StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, surveyorStationRecord, context, fragmentManager, lifecycleOwner, toleranceRecord, + cachedData, surveyorDataSource, surveyorDataSource, cachedData, @@ -252,26 +237,10 @@ public class MeasureDefaultFragment extends BaseFragment }); } - @Override - public void onResume() { - super.onResume(); - if (stateManager != null) { - stateManager.resume(); - } - } - - @Override - public void onPause() { - super.onPause(); - if (stateManager != null) { - stateManager.quite(); - } - } - public interface ICollectCacheCallback { void onFailure(); - void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManager stateManager); + void onSuccess(boolean showSlopDistance, ICachedData cachedData, SurveyorData surveyorData, StateManagerTj stateManager); } @Override @@ -299,7 +268,7 @@ public class MeasureDefaultFragment extends BaseFragment } @Override - public void deleteStationAllPeroidRecord() { + public void deleteStationAllCycleRecord() { if (stateManager == null) { return; } @@ -307,7 +276,7 @@ public class MeasureDefaultFragment extends BaseFragment } @Override - public void deleteStationOnePeriodRecord(int cycleIndex) { + public void deleteStationOneCycleRecord(int cycleIndex) { if (stateManager == null) { return; } @@ -319,15 +288,21 @@ public class MeasureDefaultFragment extends BaseFragment if (stateManager == null) { return null; } - return stateManager.stationCheckOnly(); + stateManager.stationCheck(); + return null; } @Override public void stationAdjust() { - if (stateManager == null) { - return; - } - stateManager.stationAdjustOnly(StationDataAdjustDialogFragment.TYPE_ANGLE_DISTANCE); + StationUtilPla.checkStationCanAdjust(stationId(), getMeasureWhat(), isCanAdjust -> { + if (!isCanAdjust) { + ToastUtils.showShort("测站未通过检测"); + return; + } + if (stateManager != null) { + stateManager.stationAdjust(); + } + }); } @Override @@ -350,17 +325,27 @@ public class MeasureDefaultFragment extends BaseFragment } @Override - public void refreshGoBackBtnEnable() { - if (stateManager == null || stateManager.getCachedData().pointCount() == 0) { - EventBus.getDefault().post(new RefreshGoBackButton(false)); - return; + public int measureTypePosition() { + return 0; + } + + @Override + public int getMeasureWhat() { + return StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT; + } + + @Override + public void onResumeState() { + if (stateManager != null) { + stateManager.resume(); } - stateManager.refreshGoBackBtnEnable(); } @Override - public int measureTypePosition() { - return MeasureFragment.POSITION_DIRECTION_MEASURE; + public void onPauseState() { + if (stateManager != null) { + stateManager.quite(); + } } @Override @@ -394,14 +379,14 @@ public class MeasureDefaultFragment extends BaseFragment } private static final String KEY_STATION_ID = "__station_id"; - private static final String KEY_TYPE_ANGLE_OR_DISTANCE = "__key_type_angle_or_distance"; - public static final String TAG = ComponentStationSurveyorDataListFragment.class.getName(); + private static final String KEY_WELL_TYPE = "__well_type"; + public static final String TAG = StationSurveyorWellLevelAngleDataFragment.class.getName(); - public static MeasureDefaultFragment newInstance(String stationId, String typeAngleOrDistance) { - MeasureDefaultFragment fragment = new MeasureDefaultFragment(); + public static StationSurveyorWellLevelAngleDataFragment newInstance(String stationId, String wellType) { + StationSurveyorWellLevelAngleDataFragment fragment = new StationSurveyorWellLevelAngleDataFragment(); Bundle bundle = new Bundle(); bundle.putString(KEY_STATION_ID, stationId); - bundle.putString(KEY_TYPE_ANGLE_OR_DISTANCE, typeAngleOrDistance); + bundle.putString(KEY_WELL_TYPE, wellType); fragment.setArguments(bundle); return fragment; } diff --git a/app/src/main/java/com/bingce/controlnetwork/model/AloneAdjustItem.java b/app/src/main/java/com/bingce/controlnetwork/model/AloneAdjustItem.java new file mode 100644 index 0000000..a7f059a --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/model/AloneAdjustItem.java @@ -0,0 +1,186 @@ +package com.bingce.controlnetwork.model; + +import android.os.Parcel; +import android.os.Parcelable; +import android.text.TextUtils; + +import androidx.annotation.Keep; + +/** + * 单独测距和单独测垂直角的平差结果(他们都是对一个目标的所有测回测完) + */ +@Keep +public class AloneAdjustItem implements Parcelable { + private String pointId; + private String pointName; + private double horAngle; + private double verAngle; + private double distance; + private String prismHeight; + + private boolean aloneDistance; + private boolean isMeasureDistanceNot; + private boolean isMeasureVerNot; + + private String errorMsg; + + + public AloneAdjustItem(String pointId, String pointName, double horAngle, double verAngle, double distance, String prismHeight, boolean aloneDistance, + boolean isMeasureDistanceNot, boolean isMeasureVerNot, String errorMsg) { + this.pointId = pointId; + this.pointName = pointName; + this.horAngle = horAngle; + this.verAngle = verAngle; + this.distance = distance; + this.prismHeight = prismHeight; + this.aloneDistance = aloneDistance; + this.isMeasureDistanceNot = isMeasureDistanceNot; + this.isMeasureVerNot = isMeasureVerNot; + this.errorMsg = errorMsg; + } + + public String getPointId() { + return pointId; + } + + public void setPointId(String pointId) { + this.pointId = pointId; + } + + public String getPointName() { + return pointName; + } + + public void setPointName(String pointName) { + this.pointName = pointName; + } + + public double getHorAngle() { + return horAngle; + } + + public void setHorAngle(double horAngle) { + this.horAngle = horAngle; + } + + public double getVerAngle() { + return verAngle; + } + + public void setVerAngle(double verAngle) { + this.verAngle = verAngle; + } + + public double getDistance() { + return distance; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public String getPrismHeight() { + return prismHeight; + } + + public void setPrismHeight(String prismHeight) { + this.prismHeight = prismHeight; + } + + public boolean isAloneDistance() { + return aloneDistance; + } + + public void setAloneDistance(boolean aloneDistance) { + this.aloneDistance = aloneDistance; + } + + public boolean isMeasureDistanceNot() { + return isMeasureDistanceNot; + } + + public void setMeasureDistanceNot(boolean measureDistanceNot) { + isMeasureDistanceNot = measureDistanceNot; + } + + public boolean isMeasureVerNot() { + return isMeasureVerNot; + } + + public void setMeasureVerNot(boolean measureVerNot) { + isMeasureVerNot = measureVerNot; + } + + public String getErrorMsg() { + return errorMsg; + } + + public void setErrorMsg(String errorMsg) { + this.errorMsg = errorMsg; + } + + public String getPrismHeightActual() { + if (TextUtils.isEmpty(prismHeight)) { + return "0"; + } + return prismHeight; + } + + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.pointId); + dest.writeString(this.pointName); + dest.writeDouble(this.horAngle); + dest.writeDouble(this.verAngle); + dest.writeDouble(this.distance); + dest.writeString(this.prismHeight); + dest.writeByte(this.aloneDistance ? (byte) 1 : (byte) 0); + dest.writeByte(this.isMeasureDistanceNot ? (byte) 1 : (byte) 0); + dest.writeByte(this.isMeasureVerNot ? (byte) 1 : (byte) 0); + dest.writeString(this.errorMsg); + } + + public void readFromParcel(Parcel source) { + this.pointId = source.readString(); + this.pointName = source.readString(); + this.horAngle = source.readDouble(); + this.verAngle = source.readDouble(); + this.distance = source.readDouble(); + this.prismHeight = source.readString(); + this.aloneDistance = source.readByte() != 0; + this.isMeasureDistanceNot = source.readByte() != 0; + this.isMeasureVerNot = source.readByte() != 0; + this.errorMsg = source.readString(); + } + + protected AloneAdjustItem(Parcel in) { + this.pointId = in.readString(); + this.pointName = in.readString(); + this.horAngle = in.readDouble(); + this.verAngle = in.readDouble(); + this.distance = in.readDouble(); + this.prismHeight = in.readString(); + this.aloneDistance = in.readByte() != 0; + this.isMeasureDistanceNot = in.readByte() != 0; + this.isMeasureVerNot = in.readByte() != 0; + this.errorMsg = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AloneAdjustItem createFromParcel(Parcel source) { + return new AloneAdjustItem(source); + } + + @Override + public AloneAdjustItem[] newArray(int size) { + return new AloneAdjustItem[size]; + } + }; +} diff --git a/app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorItem.java b/app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorItem.java new file mode 100644 index 0000000..9340dd7 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorItem.java @@ -0,0 +1,18 @@ +package com.bingce.controlnetwork.model; + +import androidx.annotation.Keep; + +@Keep +public class StationCheckErrorItem { + public final String pointName; + public final int cycleIndex1; + public final int cycleIndex2; + public final double difference; + + public StationCheckErrorItem(String pointName, int cycleIndex1, int cycleIndex2, double difference) { + this.pointName = pointName; + this.cycleIndex1 = cycleIndex1; + this.cycleIndex2 = cycleIndex2; + this.difference = difference; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorPoint.java b/app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorPoint.java new file mode 100644 index 0000000..52a7977 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/model/StationCheckErrorPoint.java @@ -0,0 +1,14 @@ +package com.bingce.controlnetwork.model; + +import androidx.annotation.Keep; + +@Keep +public class StationCheckErrorPoint { + public final String pointId; + public final String pointName; + + public StationCheckErrorPoint(String pointId, String pointName) { + this.pointId = pointId; + this.pointName = pointName; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationlist/StationListFragment.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationlist/StationListFragment.kt index c938732..62f34df 100644 --- a/app/src/main/java/com/bingce/controlnetwork/newui/stationlist/StationListFragment.kt +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationlist/StationListFragment.kt @@ -15,10 +15,10 @@ import com.bingce.controlnetwork.databinding.FragmentListLayoutBinding import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment import com.bingce.controlnetwork.fragment.stationdetail.SingleStationDetailAndEditFragment import com.bingce.controlnetwork.fragment.stationsurvey.StationSurveyorFragment -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment import com.bingce.controlnetwork.newui.adapter.StationListAdapter import com.bingce.controlnetwork.newui.base.BaseFragmentBinding import com.bingce.controlnetwork.newui.model.StationListBean +import com.bingce.controlnetwork.newui.stationsurveyor.StationSurveyorHomeActivity import com.bingce.controlnetwork.util.SurveyorStationUtil import com.bingce.utils.ThreadPoolUtil @@ -73,9 +73,11 @@ class StationListFragment : BaseFragmentBinding() { private fun clickStationItem(bean: StationListBean) { //StationSurveyorFragment原始测量页 if (isConnection(bean.projectType)) { - MeasureFragment.start(context, bean.stationId, bean.stationName) +// MeasureFragment.start(context, bean.stationId, bean.stationName) } else { - StationSurveyorFragment.start(context, bean.stationId, bean.stationName) + StationSurveyorHomeActivity.start(requireContext(), bean.stationId) + +// StationSurveyorFragment.start(context, bean.stationId, bean.stationName) } } diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsetting/StationSettingsActivity.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsetting/StationSettingsActivity.kt index 9f1166a..4387df5 100644 --- a/app/src/main/java/com/bingce/controlnetwork/newui/stationsetting/StationSettingsActivity.kt +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsetting/StationSettingsActivity.kt @@ -14,8 +14,10 @@ import com.bingce.controlapphelper.model.BundleConstants import com.bingce.controlapphelper.util.FastClickUtil import com.bingce.controlnetwork.R import com.bingce.controlnetwork.databinding.NewActivityStationSettingBinding +import com.bingce.controlnetwork.event.ReplaceSurveyorFragmentEvent import com.bingce.controlnetwork.newui.base.BaseBindingActivity import com.bingce.controlnetwork.util.KeyboardUtil +import org.greenrobot.eventbus.EventBus class StationSettingsActivity : BaseBindingActivity() { @@ -136,7 +138,7 @@ class StationSettingsActivity : BaseBindingActivity() { + + private val viewModel by viewModels() + + private var menuItemRollBack: MenuItem? = null + + private var stationId: String? = null + + private var menuOperate: ISurveyorMenuOperate? = null + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onReplaceSurveyorFragment(event: ReplaceSurveyorFragmentEvent) { + replaceFragment() + } + + companion object { + @JvmStatic + fun start(context: Context, stationId: String) { + context.startActivity(Intent(context, StationSurveyorHomeActivity::class.java).apply { + putExtra(BundleConstants.KEY_SURVEYOR_STATION_ID, stationId) + }) + } + } + + override fun getBinding(): NewActivityStationSurveyorHomeBinding { + return NewActivityStationSurveyorHomeBinding.inflate(layoutInflater) + } + + override fun initView() { + EventBus.getDefault().register(this) + stationId = getStationId() + initToolBarTitle() + } + + private fun initToolBarTitle() { + lifecycleScope.launch(Dispatchers.IO) { + val stationRecord = + SurveyorDatabaseFactory.instance.surveyorStation.getRecordSync(stationId) + val stationName = StationUtil.getStationName(stationRecord) + withContext(Dispatchers.Main) { + setToolbarTitle(stationName) + } + } + } + + override fun onDestroy() { + super.onDestroy() + EventBus.getDefault().unregister(this) + } + + override fun initData() { + replaceFragment() + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + if (Test.DEBUG) { + menuInflater.inflate(R.menu.menu_surveyor_station_record_data_edit_debug_pla, menu) + } else { + menuInflater.inflate(R.menu.menu_surveyor_station_record_data_edit_release_pla, menu) + } + //回退 + menuItemRollBack = menu.findItem(R.id.menu_item_go_back) + return super.onCreateOptionsMenu(menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (R.id.menu_item_delete_current_records == item.itemId) { + menuOperate?.deleteCurrentPeriodRecords() + } else if (R.id.menu_item_delete_all_records == item.itemId) { + menuOperate?.deleteAllPeriodRecords() + } else if (R.id.menu_item_data_source == item.itemId) { + menuOperate?.test() + } else if (R.id.menu_item_go_back == item.itemId) { + menuOperate?.rollBack() + } else if (R.id.menu_item_station_environment_prism_settings == item.itemId) { + menuOperate?.stationSetting() + } else if (R.id.menu_item_station_adjust == item.itemId) { + menuOperate?.adjust() + } + return super.onOptionsItemSelected(item) + } + + private fun getStationId() = intent.getStringExtra(BundleConstants.KEY_SURVEYOR_STATION_ID) + + fun setRollBackEnable(enable: Boolean) { + menuItemRollBack?.isEnabled = enable + } + + private fun replaceFragment() { + stationId?.let { stationId -> + viewModel.getStation(stationId) { + val bundle = Bundle() + bundle.putString(BundleConstants.KEY_SURVEYOR_STATION_ID, stationId) + + val beginTransaction = supportFragmentManager.beginTransaction() + + val fragment = if (TextUtils.equals(it.projectType, ProjectTypeValue.CONNECTION)) { + StationSurveyorWellFragment() + } else { + if (it.isSeparateObservation) { + //分开观测 + StationSurveyorSeparateFragment() + } else { + if (it.aloneMeasureDistance) { + StationSurveyorWellFragment() + } else { + StationSurveyorFragment() + } + } + } + + menuOperate = fragment + + fragment.arguments = bundle + + beginTransaction.replace(R.id.container, fragment) + beginTransaction.commitAllowingStateLoss() + } + } + } + + override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { + Log.d("hwhw", "StationSurveyorHomeActivity_onKeyDown==keyCode=" + keyCode) + if (keyCode == 131) { + menuOperate?.startSurveyor() + } + return super.onKeyDown(keyCode, event) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsurveyor/StationSurveyorHomeViewModel.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsurveyor/StationSurveyorHomeViewModel.kt new file mode 100644 index 0000000..3f479a7 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsurveyor/StationSurveyorHomeViewModel.kt @@ -0,0 +1,28 @@ +package com.bingce.controlnetwork.newui.stationsurveyor + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import blankj.utilcode.util.ToastUtils +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +class StationSurveyorHomeViewModel : ViewModel() { + fun getStation(stationId: String, callBack: (SurveyorStationRecord) -> Unit) { + viewModelScope.launch(Dispatchers.IO) { + val stationRecord = + SurveyorDatabaseFactory.instance.surveyorStation.getRecordSync(stationId) + if (stationRecord == null || stationRecord.items.isNullOrEmpty()) { + ToastUtils.showLong("测站数据异常") + return@launch + } + withContext(Dispatchers.Main) { + callBack(stationRecord) + } + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedData.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedData.java new file mode 100644 index 0000000..70e9a7e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedData.java @@ -0,0 +1,1086 @@ +package com.bingce.controlnetwork.surveyor.data; + +import static com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord.ALONE_DISTANCE_CYCLE_COUNT; +import static com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT; + +import android.text.TextUtils; +import android.util.Log; + +import androidx.annotation.WorkerThread; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.alonedistance.IAloneDistanceRecordDataSource; +import com.bingce.controlapphelper.datasource.database.alonedistance.WellDistance; +import com.bingce.controlapphelper.datasource.database.learn.LearnBaseDataRecord; +import com.bingce.controlapphelper.datasource.database.point.IPointDataSource; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.sdangle.ISdAngleRecordDataSource; +import com.bingce.controlapphelper.datasource.database.sdangle.SdAngleRecord; +import com.bingce.controlapphelper.datasource.database.surveyorrecord.ISurveyorRecordDataSource; +import com.bingce.controlapphelper.datasource.database.surveyorrecord.SurveyorRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.IAdapter; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.surveyor.method.DeviationValueOfRadianMethod; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/* + * 缓存的测站的测量数据 + * */ +public class CachedData implements ICachedData, IStationPointRecordCollect { + private final int measureWhat; + private final int circleCount; + private final int surveyorCount; + private final String stationId; + //数据监听 + private final List adapters = new ArrayList<>(); + //缓存的数据库中的数据 + private final StationPointCollect pointCollect; + //key = pointId + private final Map pointRecordMap; + //key = stationId + cycleIndex + pointId + leftOrRight + private final Map surveyorRecordMap; + private final Map sdAngleRecordMap; + private final Map wellRecordMap; + private boolean showSlopDistance = true; + + private CachedData(int measureWhat, String stationId, int circleCount, int surveyorCount, + boolean autoClose, boolean leftRight, + List itemListWithoutClosedItem, + Map pointRecordMap, + Map surveyorRecordMap, + Map sdAngleRecordMap, + Map wellRecordMap + ) { + this.measureWhat = measureWhat; + this.circleCount = circleCount; + this.surveyorCount = surveyorCount; + this.stationId = stationId; + this.pointCollect = new StationPointCollect(itemListWithoutClosedItem, measureWhat, autoClose, leftRight); + this.pointRecordMap = pointRecordMap; + this.surveyorRecordMap = surveyorRecordMap; + this.sdAngleRecordMap = sdAngleRecordMap; + this.wellRecordMap = wellRecordMap; + } + + @Override + public int pointCount() { + return pointCollect.size(); + } + + @Override + public int realPointCount() { + return pointCollect.realSize(); + } + + @Override + public String pointName(int cycleIndex, int itemIndex) { + String pointOriginId = pointCollect.pointOriginId(cycleIndex, itemIndex); + //常量值 + String EMPTY_POINT_NAME = "*"; + if (pointOriginId == null) { + return EMPTY_POINT_NAME; + } + PointRecord pointRecord = pointRecordMap.get(pointOriginId); + if (pointRecord == null) { + return EMPTY_POINT_NAME; + } + String pointType = pointCollect.pointType(cycleIndex, itemIndex); + if (SurveyorPoint.TYPE_POINT_CLOSE.equals(pointType)) { + return pointRecord.getName() + "-归零"; + } + return pointRecord.getName(); + } + + @Override + public String pointId(int cycleIndex, int itemIndex) { + //常量值 + return pointCollect.pointId(cycleIndex, itemIndex); + } + + @Override + public String realPointId(int cycleIndex, int itemIndex) { + return pointCollect.pointOriginId(cycleIndex, itemIndex); + } + + @Override + public boolean isClosePoint(int cycleIndex, int itemIndex) { + return pointCollect.isClosePoint(cycleIndex, itemIndex); + } + + @Override + public int getSurveyorCount() { + return surveyorCount; + } + + @Override + public boolean isWellSteelPoint(int cycleIndex, int itemIndex) { + return pointCollect.isPointSteel(cycleIndex, itemIndex); + } + + @Override + public boolean isAloneMeasureDistancePoint(int cycleIndex, int itemIndex) { + return pointCollect.isAloneMeasureDistancePoint(cycleIndex, itemIndex); + } + + @Override + public boolean isMeasureVerNot(int cycleIndex, int itemIndex) { + return pointCollect.isMeasureVerNot(cycleIndex, itemIndex); + } + + @Override + public boolean isMeasureDistanceNot(int cycleIndex, int itemIndex) { + return pointCollect.isMeasureDistanceNot(cycleIndex, itemIndex); + } + + @Override + public boolean isAbandonPoint(int cycleIndex, int itemIndex) { + return pointCollect.isPointAbandon(cycleIndex, itemIndex); + } + + @Override + public void setPointAbandon(int cycleIndex, int itemIndex) { + pointCollect.setPointAbandon(cycleIndex, itemIndex); + } + + @Override + public DataCategory valueState(String recordId) { + return valueState(recordId, 0); + } + + @Override + public DataCategory valueState(String recordId, int surveyorIndex) { + SurveyorRecord surveyorRecord = surveyorRecord(recordId); + if (surveyorRecord == null) { + return DataCategory.emptyCategory(); + } + return surveyorIndex == 0 ? + surveyorRecord.value1Status : surveyorRecord.value2Status; + } + + @Override + public double angleHor1(String recordId) { + SdAngleRecord sdAngleRecord = value1(recordId); + return sdAngleRecord == null ? 0 : sdAngleRecord.angleHor; + } + + @Override + public double angleHor2(String recordId) { + SdAngleRecord sdAngleRecord = value2(recordId); + return sdAngleRecord == null ? 0 : sdAngleRecord.angleHor; + } + + @Override + public double angleHor(String recordId) { + SdAngleRecord sdAngleRecord1 = value1(recordId); + if (sdAngleRecord1 == null) { + return 0; + } + SdAngleRecord sdAngleRecord2 = value2(recordId); + if (sdAngleRecord2 == null) { + return sdAngleRecord1.angleHor; + } + return DeviationValueOfRadianMethod.similarAverage(sdAngleRecord1.angleHor, sdAngleRecord2.angleHor); + } + + @Override + public double angleVer1(String recordId) { + SdAngleRecord sdAngleRecord = value1(recordId); + return sdAngleRecord == null ? 0 : sdAngleRecord.angleVer; + } + + @Override + public double angleVer2(String recordId) { + SdAngleRecord sdAngleRecord = value2(recordId); + return sdAngleRecord == null ? 0 : sdAngleRecord.angleVer; + } + + @Override + public double angleVer(String recordId) { + SdAngleRecord sdAngleRecord1 = value1(recordId); + if (sdAngleRecord1 == null) { + return 0; + } + SdAngleRecord sdAngleRecord2 = value2(recordId); + if (sdAngleRecord2 == null) { + return sdAngleRecord1.angleVer; + } + return DeviationValueOfRadianMethod.similarAverage(sdAngleRecord1.angleVer, sdAngleRecord2.angleVer); + } + + @Override + public double distance1(String recordId) { + SdAngleRecord sdAngleRecord = value1(recordId); + return sdAngleRecord == null ? 0 : (showSlopDistance ? sdAngleRecord.distanceSlop : sdAngleRecord.distanceHor); + } + + @Override + public double distance2(String recordId) { + SdAngleRecord sdAngleRecord = value2(recordId); + return sdAngleRecord == null ? 0 : (showSlopDistance ? sdAngleRecord.distanceSlop : sdAngleRecord.distanceHor); + } + + @Override + public double distance(String recordId) { + SdAngleRecord sdAngleRecord1 = value1(recordId); + if (sdAngleRecord1 == null) { + return 0; + } + double d1 = showSlopDistance ? sdAngleRecord1.distanceSlop : sdAngleRecord1.distanceHor; + SdAngleRecord sdAngleRecord2 = value2(recordId); + if (sdAngleRecord2 == null) { + return d1; + } + double d2 = showSlopDistance ? sdAngleRecord2.distanceSlop : sdAngleRecord2.distanceHor; + return (d1 + d2) / 2f; + } + + @Override + public double distanceSlop(String recordId) { + SdAngleRecord sdAngleRecord1 = value1(recordId); + if (sdAngleRecord1 == null) { + return 0; + } + double d1 = sdAngleRecord1.distanceSlop; + SdAngleRecord sdAngleRecord2 = value2(recordId); + if (sdAngleRecord2 == null) { + return d1; + } + double d2 = sdAngleRecord2.distanceSlop; + return (d1 + d2) / 2f; + } + + @Override + public String getPrismHeight(int cycleIndex, int itemIndex) { + return pointCollect.getPrismHeight(cycleIndex, itemIndex); + } + + @Override + public String getPrismName(int cycleIndex, int itemIndex) { + return pointCollect.getPrismName(cycleIndex, itemIndex); + } + + @Override + public String getPrismTypeName(int cycleIndex, int itemIndex) { + return pointCollect.getPrismTypeName(cycleIndex, itemIndex); + } + + @Override + public SurveyorPoint getSurveyorPoint(int cycleIndex, int itemIndex) { + return pointCollect.targetItem(cycleIndex, itemIndex); + } + + @Override + public void register(IAdapter adapter) { + if (adapters.contains(adapter)) { + return; + } + adapters.add(adapter); + } + + @Override + public void unregister(IAdapter adapter) { + adapters.remove(adapter); + } + + @Override + public void notifyDateChange() { + //通知adapter更新 + for (IAdapter adapter : adapters) { + adapter.onDataChange(); + } + } + + @Override + public void deleteSurveyorRecord(String stationId) { + //删除数据库中数据 + ThreadPoolUtil.execute(() -> { + ISurveyorRecordDataSource surveyorRecordDataSource = + SurveyorDatabaseFactory.instance.getSurveyorRecordDataSource(); + SurveyorStationRecord stationRecord = SurveyorDatabaseFactory.instance.getSurveyorStation().getRecordSync(stationId); + if (stationRecord != null && stationRecord.isSeparateObservation()) { + surveyorRecordDataSource.deleteByStation(measureWhat, stationId); + } else { + surveyorRecordDataSource.deleteByStation(stationId); + } + }); + + //删除缓存 + for (int index = 0; index < circleCount; index++) { + removeSurveyorRecord(stationId, index); + } + } + + @Override + public void deleteSurveyorRecord(String stationId, int cycleIndex) { + ThreadPoolUtil.execute(() -> { + ISurveyorRecordDataSource surveyorRecordDataSource = + SurveyorDatabaseFactory.instance.getSurveyorRecordDataSource(); + SurveyorStationRecord stationRecord = SurveyorDatabaseFactory.instance.getSurveyorStation().getRecordSync(stationId); + if (stationRecord != null && stationRecord.isSeparateObservation()) { + surveyorRecordDataSource.deleteByStationAndCycle(measureWhat, stationId, cycleIndex); + } else { + surveyorRecordDataSource.deleteByStationAndCycle(stationId, cycleIndex); + } + }); + //删除缓存 + removeSurveyorRecord(stationId, cycleIndex); + } + + @Override + public void deleteSurveyorRecord(String stationId, int cycleIndex, int itemIndex, + LeftOrRight leftOrRight) { + String key = key(cycleIndex, itemIndex, leftOrRight); + SurveyorRecord surveyorRecord = surveyorRecord(key); + if (surveyorRecord == null) { + return; + } + //删除缓存数据 + surveyorRecordMap.remove(key); + //删除数据库 + ISurveyorRecordDataSource surveyorRecordDataSource = + SurveyorDatabaseFactory.instance.getSurveyorRecordDataSource(); + surveyorRecordDataSource.deleteById(surveyorRecord.id); + } + + @WorkerThread + @Override + public boolean deleteWellDistancePointRecordOneCycle(String stationId, int itemIndex) { + String key = key(0, itemIndex, LeftOrRight.left); + AloneDistanceRecord wellDistanceRecordNew = wellRecordMap.get(key); + if (wellDistanceRecordNew == null) { + return false; + } + + boolean isDelete = false; + // + if (wellDistanceRecordNew.distanceValues.size() > surveyorCount) {//surveyorCount=4 + for (int i = wellDistanceRecordNew.distanceValues.size() - 1; i >= surveyorCount; i--) { + wellDistanceRecordNew.distanceValues.remove(i); + + //同步删除时间记录 + if (wellDistanceRecordNew.distanceCreateDate.size() > i) { + wellDistanceRecordNew.distanceCreateDate.remove(i); + } + } + } else { + wellRecordMap.remove(key); + isDelete = true; + } + + IAloneDistanceRecordDataSource wellDistanceDataSource = SurveyorDatabaseFactory.instance.getAloneDistanceRecordDataSource(); + + String pointId = getSurveyorPoint(0, itemIndex).getOriginalPointId(); + AloneDistanceRecord wellDistanceRecordBefore = wellDistanceDataSource.getRecordSync(stationId, 0, pointId); + if (isDelete) { + if (wellDistanceRecordBefore != null) { + wellDistanceDataSource.delete(wellDistanceRecordBefore); + } + } else { + wellDistanceDataSource.saveRecord(wellDistanceRecordNew); + } + + return true; + } + + @Override + public boolean deleteWellDistanceStationRecord(String stationId, int pointIndex) { + //删除缓存 + int cycleIndex = 0; + String key = key(cycleIndex, pointIndex, LeftOrRight.left); + wellRecordMap.remove(key); + IAloneDistanceRecordDataSource wellDistanceDataSource = SurveyorDatabaseFactory.instance.getAloneDistanceRecordDataSource(); + AloneDistanceRecord wellDistanceRecordBefore = wellDistanceDataSource.getRecordSync(stationId, cycleIndex, pointId(cycleIndex, pointIndex)); + if (wellDistanceRecordBefore != null) { + wellDistanceDataSource.delete(wellDistanceRecordBefore); + return true; + } + return false; + } + + @Override + public void markReSurveyor(String stationId, int cycleIndex, List pointIds) { + ISurveyorRecordDataSource surveyorRecordDataSource = SurveyorDatabaseFactory.instance.getSurveyorRecordDataSource(); + for (String id : pointIds) { + SurveyorRecord recordLeft = surveyorRecordMap.get( + IdUtil.surveyorRecordKey(stationId, cycleIndex, id, LeftOrRight.left)); + if (recordLeft != null) { + recordLeft.value1Status = DataCategory.needResurvey(); + recordLeft.value2Status = DataCategory.needResurvey(); + + surveyorRecordDataSource.save(recordLeft); + } + + SurveyorRecord recordRight = surveyorRecordMap.get( + IdUtil.surveyorRecordKey(stationId, cycleIndex, id, LeftOrRight.right)); + if (recordRight != null) { + recordRight.value1Status = DataCategory.needResurvey(); + recordRight.value2Status = DataCategory.needResurvey(); + + surveyorRecordDataSource.save(recordRight); + } + } + + //如果有闭合数据,将其也设置为被测 + int itemCount = pointCollect.size(); + String pointType = pointCollect.pointType(cycleIndex, itemCount - 1); + if (SurveyorPoint.TYPE_POINT_CLOSE.equals(pointType)) { + String pointId = pointCollect.pointId(cycleIndex, itemCount - 1); + SurveyorRecord recordLeft = surveyorRecordMap.get( + IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left)); + if (recordLeft != null) { + recordLeft.value1Status = DataCategory.needResurvey(); + recordLeft.value2Status = DataCategory.needResurvey(); + surveyorRecordDataSource.save(recordLeft); + } + + SurveyorRecord recordRight = surveyorRecordMap.get( + IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right)); + if (recordRight != null) { + recordRight.value1Status = DataCategory.needResurvey(); + recordRight.value2Status = DataCategory.needResurvey(); + surveyorRecordDataSource.save(recordRight); + } + } + } + + @Override + public boolean isSingleCycleAllDataValidate(int cycleIndex) { + //判断数据是否正常 + for (int index = 0; index < pointCount(); index++) { + if (isAbandonPoint(cycleIndex, index)) { + continue; + } + + String leftKey = key(cycleIndex, index, LeftOrRight.left); + String rightKey = key(cycleIndex, index, LeftOrRight.right); + if (valueState(leftKey).isValidateData() && + valueState(rightKey).isValidateData()) { + continue; + } + return false; + } + return true; + } + + @Override + public boolean isSingleCycleAllDataValidateWell(int cycleIndex) { + //判断数据是否正常 + boolean isVerify = true; + for (int index = 0; index < realPointCount(); index++) { + String leftOrRightKey = key(cycleIndex, index, LeftOrRight.left); + boolean wellRecordVerify = isWellRecordVerify(leftOrRightKey); + if (!wellRecordVerify) { + isVerify = false; + } + } + return isVerify; + } + + public boolean isWellRecordVerify(String cacheKey) { + boolean isVerify = true; + AloneDistanceRecord wellRecord = getWellRecord(cacheKey); + if (wellRecord == null || wellRecord.distanceValues == null || + wellRecord.distanceValues.size() < surveyorCount * 2) { + isVerify = false; + } + return isVerify; + } + + @Override + public void cache(int measureWhat, int cycleIndex, ISurveyorData surveyorData, CallBackCache callBackCache) { + int itemIndex = surveyorData.currentIndex(); + String pointId = pointCollect.pointId(cycleIndex, itemIndex); + if (pointId == null || pointId.isEmpty()) { + callBackCache.failure(); + return; + } + _updateSurveyor2Cache(measureWhat, pointId, + cycleIndex, + stationId, + surveyorData.dataCategory(), + this, + surveyorData, callBackCache); + } + + @Override + public AloneDistanceRecord cacheWellDistance(int cycleIndex, int itemIndex, double slopDistance, double horDistance) { + //先存储数据 + String pointId = pointCollect.pointId(cycleIndex, itemIndex); + if (pointId == null || pointId.isEmpty()) { + return null; + } + + IAloneDistanceRecordDataSource wellDataSource = SurveyorDatabaseFactory.instance.getAloneDistanceRecordDataSource(); + //执行存储,并通知更新 + String key = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + AloneDistanceRecord wellRecord = getWellRecord(key); + if (wellRecord == null) { + wellRecord = new AloneDistanceRecord(stationId, cycleIndex, pointId, LeftOrRight.left); + wellRecordMap.put(key, wellRecord); + } + + if (wellRecord.distanceValues == null) { + wellRecord.distanceValues = new ArrayList<>(); + } + if (wellRecord.distanceCreateDate == null) { + wellRecord.distanceCreateDate = new ArrayList<>(); + } + + if (wellRecord.distanceValues.size() < surveyorCount * 2) { + wellRecord.distanceValues.add(new WellDistance(slopDistance, horDistance)); + wellRecord.distanceCreateDate.add(System.currentTimeMillis()); + + AloneDistanceRecord finalWellRecord = wellRecord; + ThreadPoolUtil.execute(() -> wellDataSource.saveRecord(finalWellRecord)); + } + + return wellRecord; + } + + private void removeSurveyorRecord(String stationId, int cycleIndex) { + for (int index = 0; index < pointCollect.size(); index++) { + String pointId = pointCollect.pointId(cycleIndex, index); + if (pointId == null) { + continue; + } + surveyorRecordMap.remove( + IdUtil.surveyorRecordKey( + stationId, cycleIndex, pointId, LeftOrRight.left)); + surveyorRecordMap.remove( + IdUtil.surveyorRecordKey( + stationId, cycleIndex, pointId, LeftOrRight.right)); + } + } + + SurveyorRecord surveyorRecord(String recordId) { + return surveyorRecordMap.get(recordId); + } + + SdAngleRecord value1(String key) { + SurveyorRecord surveyorRecord = surveyorRecord(key); + if (surveyorRecord == null) { + return null; + } + return sdAngleRecordMap.get(surveyorRecord.value1Id); + } + + SdAngleRecord value2(String key) { + SurveyorRecord surveyorRecord = surveyorRecord(key); + if (surveyorRecord == null) { + return null; + } + return sdAngleRecordMap.get(surveyorRecord.value2Id); + } + + @Override + public void onShowSlopDistance(boolean value) { + this.showSlopDistance = value; + } + + private String key(int cycleIndex, int itemIndex, LeftOrRight leftOrRight) { + String pointId = pointCollect.pointId(cycleIndex, itemIndex); + return IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, leftOrRight); + } + + @Override + public SurveyorRecord getSurveyorRecord(String key) { + return surveyorRecordMap.get(key); + } + + /** + * @param key + * @return + */ + @Override + public AloneDistanceRecord getWellRecord(String key) { + return wellRecordMap.get(key); + } + + @Override + public void updateSurveyPointParams(SurveyorPoint item) { + pointCollect.updateSurveyPointParams(item); + } + + @Override + public void saveLeanRecord(int measureWhat, String pointId, ISurveyorData surveyorData, CallBackCache callBackCache) { + ThreadPoolUtil.execute(() -> { + LearnBaseDataRecord learnBaseDataRecord = SurveyorDatabaseFactory.instance.getLearnDataSource().queryByStationPointIdMeasureWhat(measureWhat, stationId, pointId); + if (learnBaseDataRecord == null) { + double angleHor = surveyorData.getAngleHor(); + double angleVer = surveyorData.getAngleVer(); + double slopDistance = surveyorData.getSlopDistance(); + double horDistance = surveyorData.getHorDistance(); + learnBaseDataRecord = new LearnBaseDataRecord(measureWhat, stationId, pointId, angleHor, angleVer, horDistance, slopDistance); + SurveyorDatabaseFactory.instance.getLearnDataSource().save(learnBaseDataRecord); + } + callBackCache.success(); + }); + } + + @Override + public void updateCache(SurveyorRecord record) { + String key = IdUtil.surveyorRecordKey(record.stationId, record.cycleIndex, record.pointId, record.leftOrRight); + surveyorRecordMap.put(key, record); + //存储数据库 + SurveyorDatabaseFactory + .instance + .getSurveyorRecordDataSource() + .save(record); + } + + @Override + public void updateCache(SdAngleRecord record) { + if (record == null) { + return; + } + sdAngleRecordMap.put(record.id, record); + //存储数据库 + SurveyorDatabaseFactory + .instance + .getSdAngleRecordDataSource() + .save(record); + } + + //IStationPointRecordCollect + @Override + public PointRecord pointRecord(int cycleIndex, int itemIndex) { + String pointOriginId = pointCollect.pointOriginId(cycleIndex, itemIndex); + if (pointOriginId == null) { + return null; + } + return pointRecordMap.get(pointOriginId); + } + + private static class StationPointCollect { + private final List itemListWithoutClosedItem; + private final boolean autoClose; + private final boolean leftRight;//左右角测量标识 + private final int measureWhat;//对应StateContant + + StationPointCollect(List items, int measureWhat, boolean autoClose, boolean leftRight) { + this.itemListWithoutClosedItem = items; + this.autoClose = autoClose; + this.leftRight = leftRight; + this.measureWhat = measureWhat; + } + + int size() { + int extra = 0; + if (!(StateConstantsTj.isMeasureVerAngle(measureWhat) || StateConstantsTj.isMeasureDistance(measureWhat))) { + if (autoClose) { + extra = 1; + } + } + return originSize() + extra; + } + + int realSize() { + return originSize(); + } + + boolean isPointSteel(int cycleIndex, int itemIndex) { + boolean isWellSteel = false; + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target != null) { + isWellSteel = target.isWellSteel(); + } + return isWellSteel; + } + + boolean isAloneMeasureDistancePoint(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + boolean isAloneMeasureDistance = false; + if (target != null) { + isAloneMeasureDistance = target.isAloneMeasureDistance(); + } + return isAloneMeasureDistance; + } + + boolean isMeasureVerNot(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + boolean isMeasureVerNot = false; + if (target != null) { + isMeasureVerNot = target.isMeasureVerNot(); + } + return isMeasureVerNot; + } + + boolean isMeasureDistanceNot(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + boolean isMeasureDistanceNot = false; + if (target != null) { + isMeasureDistanceNot = target.isMeasureDistanceNot(); + } + return isMeasureDistanceNot; + } + + boolean isPointAbandon(int cycleIndex, int itemIndex) { + boolean isAbandon = false; + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target != null) { + isAbandon = target.isAbandon(); + } + return isAbandon; + } + + String pointId(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target == null) { + return null; + } + if (itemIndex >= originSize() && autoClose) { + return SurveyorPoint.pointClosedId(target.getOriginalPointId()); + } + return target.getPointId(); + } + + String pointOriginId(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target == null) { + return null; + } + return target.getOriginalPointId(); + } + + String pointType(int cycleIndex, int itemIndex) { + if (itemIndex >= originSize() && autoClose) { + return SurveyorPoint.TYPE_POINT_CLOSE; + } + return SurveyorPoint.TYPE_POINT; + } + + boolean isClosePoint(int cycleIndex, int itemIndex) { + if (itemIndex >= originSize() && autoClose) { + return true; + } + return false; + } + + String getPrismHeight(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target == null) { + return ""; + } + return target.getPrismHeight(); + } + + String getPrismName(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target == null) { + return ""; + } + return target.getPrismName(); + } + + String getPrismTypeName(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target == null) { + return ""; + } + return target.getPrismTypeName(); + } + + private int originSize() { + return itemListWithoutClosedItem.size(); + } + + public SurveyorPoint targetItem(int cycleIndex, int itemIndex) { + int originSize = originSize(); + //当是分开观测垂直角观察幕刃 + if (StateConstantsTj.needLeftRight(measureWhat) + && leftRight && cycleIndex % 2 == 1) { + //当开启左右角测量且是偶数测回的时候 + //右角测量 + if (originSize > 0 && itemIndex >= originSize && autoClose) { + return itemListWithoutClosedItem.get(originSize - 1); + } else if (itemIndex < originSize) { + return itemListWithoutClosedItem.get(originSize - 1 - itemIndex); + } + } else {//左角测量 + if (originSize > 0 && itemIndex >= originSize && autoClose) { + return itemListWithoutClosedItem.get(0); + } else if (itemIndex < originSize && itemIndex >= 0) { + return itemListWithoutClosedItem.get(itemIndex); + } + } + return null; + } + + public void updateSurveyPointParams(SurveyorPoint surveyorPoint) { + for (SurveyorPoint current : itemListWithoutClosedItem) { + String pointId = surveyorPoint.getOriginalPointId(); + if (!TextUtils.equals(pointId, current.getOriginalPointId())) { + continue; + } + current.setPrismTypeName(surveyorPoint.getPrismTypeName()); + current.setPrismTypeConstant(surveyorPoint.getPrismTypeConstant()); + current.setPrismType(surveyorPoint.getPrismType()); + current.setPrismTypeLarge(surveyorPoint.getPrismTypeLarge()); + current.setPrismHeight(surveyorPoint.getPrismHeight()); + current.setAloneMeasureDistance(surveyorPoint.isAloneMeasureDistance()); + } + } + + public void setPointAbandon(int cycleIndex, int itemIndex) { + SurveyorPoint target = targetItem(cycleIndex, itemIndex); + if (target != null) { + target.setAbandon(true); + } + } + } + + /* + * 收集测站信息,创建测量数据缓存实例 + * 会阻塞线程 + * */ + @WorkerThread + public static CachedData newInstance(int measureWhat, CachedDataPointType cachedDataPointType, boolean autoClose, + boolean leftRight, String stationId, + ToleranceDetailRecord toleranceRecord) { + SurveyorStationRecord stationRecord = SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + + //1.读取测点数据 + List itemListWithoutClosedItem = StationUtilPla.itemListWithoutClosedItems(stationRecord, stationId, cachedDataPointType); + if (itemListWithoutClosedItem == null) { + return null; + } + //2.读取相关数据 + Map pointRecordMap = new HashMap<>(); + IPointDataSource pointDataSource = SurveyorDatabaseFactory.instance.getPointDataSource(); + + //井定向两行代码 + Map wellDistanceRecordMap = new HashMap<>(); + IAloneDistanceRecordDataSource wellDistanceDataSource = SurveyorDatabaseFactory.instance.getAloneDistanceRecordDataSource(); + + //缓存点数据 + for (SurveyorPoint item : itemListWithoutClosedItem) { + PointRecord pointRecord = pointDataSource.findByIdSync(item.getOriginalPointId()); + if (pointRecord != null) { + pointRecordMap.put(pointRecord.id, pointRecord); + } + + //缓存单独测距的数据 + if (likeWellSteel(cachedDataPointType)) { + //当是钢丝点或无棱镜的时候 + String key = IdUtil.surveyorRecordKey(stationId, 0, item.getOriginalPointId(), LeftOrRight.left); + AloneDistanceRecord wellDistanceRecord = wellDistanceDataSource.getRecordSync(stationId, 0, item.getOriginalPointId()); + wellDistanceRecordMap.put(key, wellDistanceRecord); + } + + } + //3.缓存测量数据和角数据 + Map surveyorRecordMap = new HashMap<>(); + Map sdAngleRecordMap = new HashMap<>(); + //4.读取所有测回的数据 + int cycleCount = StationUtilPla.getCycleCount(measureWhat, stationRecord, toleranceRecord); + for (int index = 0; index < cycleCount; index++) { + _collectSdAngleRecord(measureWhat, autoClose, itemListWithoutClosedItem, stationId, index, surveyorRecordMap, sdAngleRecordMap); + } + + //获取单点测量的测量次数 + int surveyorCount = toleranceRecord.getSurveyorCount(); + if (likeWellSteel(cachedDataPointType)) { + cycleCount = ALONE_DISTANCE_CYCLE_COUNT; + surveyorCount = ALONE_DISTANCE_MEASURE_COUNT; + } + + //5.创建实例 + return new CachedData(measureWhat, stationId, cycleCount, + surveyorCount, + autoClose, leftRight, + itemListWithoutClosedItem, pointRecordMap, surveyorRecordMap, sdAngleRecordMap, wellDistanceRecordMap); + } + + + private static void _collectSdAngleRecord(int measureWhat, boolean autoClose, List itemListWithoutClosedItem, + String stationId, int cycleIndex, + Map surveyorRecordMap, + Map sdAngleRecordMap) { + ISurveyorRecordDataSource surveyorRecordDataSource = SurveyorDatabaseFactory.instance.getSurveyorRecordDataSource(); + ISdAngleRecordDataSource sdAngleRecordDataSource = SurveyorDatabaseFactory.instance.getSdAngleRecordDataSource(); + for (SurveyorPoint item : itemListWithoutClosedItem) { + _cacheRecord(measureWhat, item.getPointId(), stationId, cycleIndex, + surveyorRecordDataSource, sdAngleRecordDataSource, surveyorRecordMap, sdAngleRecordMap); + } + //添加闭合点数据 + if (StateConstantsTj.isZeroMeasureWhat(measureWhat) && !itemListWithoutClosedItem.isEmpty() && autoClose) { + SurveyorPoint item = itemListWithoutClosedItem.get(0); + _cacheRecord(measureWhat, SurveyorPoint.pointClosedId(item.getPointId()), stationId, cycleIndex, + surveyorRecordDataSource, sdAngleRecordDataSource, surveyorRecordMap, sdAngleRecordMap); + } + } + + private static void _cacheRecord( + int measureWhat, + String pointId, + String stationId, int cycleIndex, + ISurveyorRecordDataSource surveyorRecordDataSource, + ISdAngleRecordDataSource sdAngleRecordDataSource, + Map surveyorRecordMap, + Map sdAngleRecordMap) { + SurveyorRecord surveyorRecordLeft = surveyorRecordDataSource + .getRecordSync(measureWhat, stationId, cycleIndex, pointId, LeftOrRight.left); + if (surveyorRecordLeft != null) { + surveyorRecordMap.put(IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left), surveyorRecordLeft); + _getSdAngleData(surveyorRecordLeft.value1Id, sdAngleRecordDataSource, sdAngleRecordMap); + _getSdAngleData(surveyorRecordLeft.value2Id, sdAngleRecordDataSource, sdAngleRecordMap); + } + SurveyorRecord surveyorRecordRight = surveyorRecordDataSource + .getRecordSync(measureWhat, stationId, cycleIndex, pointId, LeftOrRight.right); + if (surveyorRecordRight != null) { + surveyorRecordMap.put(IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right), surveyorRecordRight); + _getSdAngleData(surveyorRecordRight.value1Id, sdAngleRecordDataSource, sdAngleRecordMap); + _getSdAngleData(surveyorRecordRight.value2Id, sdAngleRecordDataSource, sdAngleRecordMap); + } + } + + private static void _getSdAngleData(String id, ISdAngleRecordDataSource sdAngleRecordDataSource, Map sdAngleRecordMap) { + if (id != null) { + SdAngleRecord sdAngleRecord = sdAngleRecordDataSource.getSync(id); + Log.d("hwhw", sdAngleRecord.id); + Log.d("hwhw", "sdAngleRecord.angleVer=" + sdAngleRecord.angleVer); + + if (sdAngleRecord != null) { + sdAngleRecordMap.put(id, sdAngleRecord); + } + } + } + + + /** + * 从当前测量数据中提取数据,更新到缓存中 + */ + private static void _updateSurveyor2Cache(int measureWhat, + String pointId, + int cycleIndex, + String stationId, + DataCategory category, + ICachedData cachedDataSource, + ISurveyorData surveyorData, + CallBackCache callBackCache) { + LeftOrRight leftOrRight = surveyorData.leftOrRight(); + //执行存储,并通知更新 + String key = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, leftOrRight); + SurveyorRecord surveyorRecord = cachedDataSource.getSurveyorRecord(key); + if (surveyorRecord == null) { + surveyorRecord = new SurveyorRecord(measureWhat, stationId, cycleIndex, pointId, leftOrRight); + } + SdAngleRecord sdAngleRecord1 = _readSdAngleFromSurveyor(_VALUE_1_2.value1, + stationId, cycleIndex, pointId, category, + surveyorRecord, surveyorData); + if (sdAngleRecord1 != null) { + //存测量数据一 + cachedDataSource.updateCache(sdAngleRecord1); + } + SdAngleRecord sdAngleRecord2 = _readSdAngleFromSurveyor(_VALUE_1_2.value2, + stationId, cycleIndex, pointId, category, + surveyorRecord, surveyorData); + if (sdAngleRecord2 != null) { + //存测量数据二 + cachedDataSource.updateCache(sdAngleRecord2); + } + //存测量记录 + cachedDataSource.updateCache(surveyorRecord); + //存学习数据 + cachedDataSource.saveLeanRecord(measureWhat, pointId, surveyorData, callBackCache); + } + + private enum _VALUE_1_2 { + value1, + value2 + } + + /** + * 从测量数据中读取sda记录 + * + * @return sda实例 + */ + private static SdAngleRecord _readSdAngleFromSurveyor(_VALUE_1_2 value_1_2, + String stationId, + int periodIndex, + String pointId, + DataCategory category, + SurveyorRecord surveyorRecord, + ISurveyorData surveyorData) { + switch (value_1_2) { + case value1: + if (surveyorRecord.value1Status.isNeedResurvey()) { + surveyorRecord.value1Status = DataCategory.dirtyAndSurveyed; + } else { + surveyorRecord.value1Status = category; + } + break; + case value2: + if (surveyorRecord.value2Status.isNeedResurvey()) { + surveyorRecord.value2Status = DataCategory.dirtyAndSurveyed; + } else { + surveyorRecord.value2Status = category; + } + break; + } + boolean hasValue = false; + switch (value_1_2) { + case value1: + hasValue = surveyorData.hasSurveyor1(); + break; + case value2: + hasValue = surveyorData.hasSurveyor2(); + break; + } + if (hasValue && category.isNormalData()) { + SdAngleRecord sdAngleRecord = + new SdAngleRecord( + stationId, + periodIndex, + pointId, + value_1_2 == _VALUE_1_2.value1 ? surveyorData.getAngleHor1() : surveyorData.getAngleHor2(), + value_1_2 == _VALUE_1_2.value1 ? surveyorData.getAngleVer1() : surveyorData.getAngleVer2(), + value_1_2 == _VALUE_1_2.value1 ? surveyorData.getHorDistance1() : surveyorData.getHorDistance2(), + value_1_2 == _VALUE_1_2.value1 ? surveyorData.getSlopDistance1() : surveyorData.getSlopDistance2()); + switch (value_1_2) { + case value1: + surveyorRecord.value1Id = sdAngleRecord.id; + break; + case value2: + surveyorRecord.value2Id = sdAngleRecord.id; + break; + } + return sdAngleRecord; + } + return null; + } + + private static boolean likeWellSteel(CachedDataPointType cachedDataPointType) { + return cachedDataPointType == CachedDataPointType.STEEL_POINT || cachedDataPointType == CachedDataPointType.ALONE_MEASURE_DISTANCE_POINT; + } + + @Override + public boolean isHasData(int cycleIndex, int itemIndex, LeftOrRight leftOrRight) { + String key = key(cycleIndex, itemIndex, leftOrRight); + SurveyorRecord surveyorRecord = surveyorRecord(key); + return surveyorRecord != null; + } + + @Override + public boolean isShowSlopDistance() { + return showSlopDistance; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedDataPointType.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedDataPointType.java new file mode 100644 index 0000000..23528d2 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/CachedDataPointType.java @@ -0,0 +1,8 @@ +package com.bingce.controlnetwork.surveyor.data; + +public enum CachedDataPointType { + ALL_POINT, + STEEL_POINT, + ALONE_MEASURE_DISTANCE_POINT, + ALONE_MEASURE_VER_ANGLE_POINT +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/FaultTolerantData.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/FaultTolerantData.java new file mode 100644 index 0000000..4207464 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/FaultTolerantData.java @@ -0,0 +1,16 @@ +package com.bingce.controlnetwork.surveyor.data; + +/** + * 容错常量 + */ +public class FaultTolerantData { + + /** + * 井定向写死的垂直和距离错误的值 + */ + public static final double WELL_ERROR_VER_ANGLE = Math.PI * 3;//写成这个数为了后面计算出负数就不显示了 + public static final double ERROR_DISTANCE = -1; + public static final double ERROR_HOR_ANGLE = -1;//弧度 + public static final double ERROR_VER_ANGLE = Double.MIN_VALUE;//弧度 + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICachedData.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICachedData.java new file mode 100644 index 0000000..85b181f --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICachedData.java @@ -0,0 +1,155 @@ +package com.bingce.controlnetwork.surveyor.data; + +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.sdangle.SdAngleRecord; +import com.bingce.controlapphelper.datasource.database.surveyorrecord.SurveyorRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.IAdapter; +import com.bingce.controlapphelper.model.LeftOrRight; + +import java.util.List; + +public interface ICachedData extends IDistanceTypeChangeListener { + //点个数 改变过 + int pointCount(); + + //实际的点的个数 + int realPointCount(); + + //点名 + String pointName(int cycleIndex, int itemIndex); + + //id + String pointId(int cycleIndex, int itemIndex); + + String realPointId(int cycleIndex, int itemIndex); + + boolean isClosePoint(int cycleIndex, int itemIndex); + + int getSurveyorCount(); + + SurveyorPoint getSurveyorPoint(int cycleIndex, int itemIndex); + + /** + * 新加 判断这个点是否是井定向钢丝点 + * + * @param cycleIndex + * @param itemIndex + * @return + */ + boolean isWellSteelPoint(int cycleIndex, int itemIndex); + + boolean isAloneMeasureDistancePoint(int cycleIndex, int itemIndex);//是否是单独测距点 + + boolean isMeasureVerNot(int cycleIndex, int itemIndex);//是否观测垂直角 + + boolean isMeasureDistanceNot(int cycleIndex, int itemIndex);//是否观测距离 + + boolean isAbandonPoint(int cycleIndex, int itemIndex); + + void setPointAbandon(int cycleIndex, int itemIndex); + + //数据状态 + DataCategory valueState(String recordId); + + DataCategory valueState(String recordId, int surveyorIndex); + + //获取相应点的测量值 + double angleHor1(String recordId); + + double angleHor2(String recordId); + + double angleHor(String recordId); + + double angleVer1(String recordId); + + double angleVer2(String recordId); + + double angleVer(String recordId); + + double distance1(String recordId); + + double distance2(String recordId); + + double distance(String recordId); + + double distanceSlop(String recordId); + + //棱镜 + String getPrismHeight(int cycleIndex, int itemIndex); + + String getPrismName(int cycleIndex, int itemIndex); + + String getPrismTypeName(int cycleIndex, int itemIndex); + + //注册数据监听 + void register(IAdapter adapter); + + void unregister(IAdapter adapter); + + void notifyDateChange(); + + //删除站的所有测回数据 + void deleteSurveyorRecord(String stationId); + + void deleteSurveyorRecord(String stationId, int cycleIndex); + + + void deleteSurveyorRecord(String stationId, int cycleIndex, int itemIndex, LeftOrRight leftOrRight); + + /** + * 回退节点或者单测回 + */ + boolean deleteWellDistancePointRecordOneCycle(String stationId, int pointIndex); + + boolean deleteWellDistanceStationRecord(String stationId, int pointIndex); + + //设置补测标识 + void markReSurveyor(String stationId, int cycleIndex, List pointIds); + + /** + * 是否完成测量--确保所有数据都正确(dirty 或 resurveyed 返回false) + * 只检测缓存数据,不考虑当前测量数据 + * + * @param cycleIndex 要检测的测回 + * @return true该测回完成测量 + */ + boolean isSingleCycleAllDataValidate(int cycleIndex); + + boolean isSingleCycleAllDataValidateWell(int cycleIndex); + + //缓存当前测量数据,并将最新数据存储到数据库中 + void cache(int measureWhat, int cycleIndex, ISurveyorData surveyorDataSource, CallBackCache cache); + + AloneDistanceRecord cacheWellDistance(int cycleIndex, int itemIndex, double slopDistance, double horDistance); + + SurveyorRecord getSurveyorRecord(String key); + + void updateCache(SurveyorRecord record); + + void updateCache(SdAngleRecord record); + + /** + * 新加 + * + * @param key + * @return + */ + AloneDistanceRecord getWellRecord(String key); + + void updateSurveyPointParams(SurveyorPoint item); + + void saveLeanRecord(int measureWhat, String pointId, ISurveyorData surveyorData, CallBackCache callBackCache); + + boolean isHasData(int cycleIndex, int itemIndex, LeftOrRight leftOrRight); + + boolean isShowSlopDistance(); + + interface CallBackCache { + void success(); + + void failure(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICycleRecorder.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICycleRecorder.java new file mode 100644 index 0000000..2153458 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ICycleRecorder.java @@ -0,0 +1,8 @@ +package com.bingce.controlnetwork.surveyor.data; + +public interface ICycleRecorder { + //测回 + int currentCycleIndex(); + + void changeCycleIndex(int cycleIndex); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/IDistanceTypeChangeListener.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/IDistanceTypeChangeListener.java new file mode 100644 index 0000000..ecbd887 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/IDistanceTypeChangeListener.java @@ -0,0 +1,8 @@ +package com.bingce.controlnetwork.surveyor.data; + +public interface IDistanceTypeChangeListener { + /** + * @param value true,显示斜距;false,显示平距 + */ + void onShowSlopDistance(boolean value); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/IStationPointRecordCollect.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/IStationPointRecordCollect.java new file mode 100644 index 0000000..a487976 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/IStationPointRecordCollect.java @@ -0,0 +1,8 @@ +package com.bingce.controlnetwork.surveyor.data; + + +import com.bingce.controlapphelper.datasource.database.point.PointRecord; + +public interface IStationPointRecordCollect { + PointRecord pointRecord(int cycleIndex, int itemIndex); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ISurveyorData.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ISurveyorData.java new file mode 100644 index 0000000..f7088f6 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/ISurveyorData.java @@ -0,0 +1,83 @@ +package com.bingce.controlnetwork.surveyor.data; + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; + +/* + * 测量数据接口 + * + * 不仅记录当前测量数据,还记录当前测量进度---测期、目标点、盘左or盘右 + * */ +public interface ISurveyorData extends IDistanceTypeChangeListener { + double getAngleHor1(); + + double getAngleVer1(); + + double getDistance1(); + + double getSlopDistance1(); + + double getHorDistance1(); + + double getAngleHor2(); + + double getAngleVer2(); + + double getDistance2(); + + double getSlopDistance2(); + + double getHorDistance2(); + + double getAngleHor(); + + double getAngleVer(); + + double getDistance(); + + double getSlopDistance(); + + double getHorDistance(); + + boolean onSurveyor(double angleHor, double angleVer, double slopDistance, double horDistance); + + void clearSurveyStateAndPosition(); + + void clearSurveyState(); + + boolean hasSurveyor1(); + + boolean hasSurveyor2(); + + void restoreSurveyor1(); + + /** + * 是否测量完成 + * + * @return true;已经可以存储 + */ + boolean ready2Record(); + + int surveyorCount(); + + //当前测点的索引 + int currentIndex(); + + void setCurrentIndex(int index); + + //设置当前正在测量的stationItem是测量盘左or盘右 + LeftOrRight leftOrRight(); + + void setLeftOrRight(LeftOrRight surveyorState); + + //数据类型 + DataCategory dataCategory(); + + void setDataCategory(DataCategory category); + + //当前测点的索引 + int getMeasureTimes(); + + void setMeasureTimes(int times); + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/SpeakCache.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/SpeakCache.java new file mode 100644 index 0000000..29f5cff --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/SpeakCache.java @@ -0,0 +1,39 @@ +package com.bingce.controlnetwork.surveyor.data; + +import java.util.HashSet; +import java.util.Set; + +public class SpeakCache { + + private static SpeakCache instance; + + private final Set cacheSet = new HashSet<>(); + + //刚切换测回已经播放的时候 + private static final int VALUE_SPEAK_SWITCH_CYCLE = 1; + + private SpeakCache() { + + } + + public static SpeakCache getInstance() { + if (instance == null) { + instance = new SpeakCache(); + } + return instance; + } + + public void saveSpeakSwitchCycle() { + cacheSet.add(VALUE_SPEAK_SWITCH_CYCLE); + } + + public void removeSpeakSwitchCycle() { + cacheSet.remove(VALUE_SPEAK_SWITCH_CYCLE); + } + + public boolean isSpeakSwitchCycle() { + return cacheSet.contains(VALUE_SPEAK_SWITCH_CYCLE); + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/data/SurveyorData.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/SurveyorData.java new file mode 100644 index 0000000..6bac2d4 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/data/SurveyorData.java @@ -0,0 +1,245 @@ +package com.bingce.controlnetwork.surveyor.data; + + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.surveyor.method.DeviationValueOfRadianMethod; + +public class SurveyorData implements ISurveyorData, ICycleRecorder { + //测量进度index + private static final int INDEX_NEVER_SURVEYOR = -1;//没有执行过测量 + private static final int INDEX_1_SURVEYOR = 0;//第一次测量完成 + private static final int INDEX_2_SURVEYOR = 1;//第二次测量完成 + + //测量进度 + private LeftOrRight surveyorState;//当前测量盘左or盘右 + private int currentItemIndex;//当前测点索引 + //测回 + private int currentCycleIndex;//当前测期的索引 + //数据类型 + private DataCategory dataCategory = DataCategory.emptyCategory(); + + private final int surveyorCount;//每个测点测量的次数 + //当前测点的测量进度 + private int currentItemSurveyorSchedule = INDEX_NEVER_SURVEYOR;//-1.都没测量;0.第一次测量完成 1.第二次测量完成 + //第一次测量数据 + private double currentAngleHor1 = 0; + private double currentAngleVer1 = 0; + private double currentSlopDistance1 = 0; + private double currentHorDistance1 = 0; + //第二次测量数据 + private double currentAngleHor2 = 0; + private double currentAngleVer2 = 0; + private double currentSlopDistance2 = 0; + private double currentHorDistance2 = 0; + + private boolean showSlopDistance = true; + + private int measureTimes = 0; + + public SurveyorData(int surveyorCount) { + this.surveyorCount = surveyorCount; + clearSurveyStateAndPosition(); + } + + @Override + public void onShowSlopDistance(boolean value) { + showSlopDistance = value; + } + + public double getAngleHor1() { + return currentAngleHor1; + } + + public double getAngleVer1() { + return currentAngleVer1; + } + + public double getDistance1() { + return showSlopDistance ? currentSlopDistance1 : currentHorDistance1; + } + + @Override + public double getSlopDistance1() { + return currentSlopDistance1; + } + + @Override + public double getHorDistance1() { + return currentHorDistance1; + } + + public double getAngleHor2() { + return currentAngleHor2; + } + + public double getAngleVer2() { + return currentAngleVer2; + } + + public double getDistance2() { + return showSlopDistance ? currentSlopDistance2 : currentHorDistance2; + } + + public double getAngleHor() { + if (surveyorCount == 1) { + return getAngleHor1(); + } + return DeviationValueOfRadianMethod.similarAverage(getAngleHor1(), getAngleHor2()); + } + + public double getAngleVer() { + if (surveyorCount == 1) { + return getAngleVer1(); + } + return DeviationValueOfRadianMethod.similarAverage(getAngleVer1(), getAngleVer2()); + } + + public double getDistance() { + if (surveyorCount == 1) { + return getDistance1(); + } + return (getDistance1() + getDistance2()) / 2f; + } + + public double getSlopDistance() { + if (surveyorCount == 1) { + return getSlopDistance1(); + } + return (getSlopDistance1() + getSlopDistance2()) / 2f; + } + + @Override + public double getHorDistance() { + if (surveyorCount == 1) { + return getHorDistance1(); + } + return (getHorDistance1() + getHorDistance2()) / 2f; + } + + @Override + public double getSlopDistance2() { + return currentSlopDistance2; + } + + @Override + public double getHorDistance2() { + return currentHorDistance2; + } + + public boolean onSurveyor(double angleHor, double angleVer, double slopDistance, double horDistance) { + boolean result = false; + if (INDEX_NEVER_SURVEYOR == currentItemSurveyorSchedule || surveyorCount == 1) { + currentAngleHor1 = angleHor; + currentAngleVer1 = angleVer; + currentSlopDistance1 = slopDistance; + currentHorDistance1 = horDistance; + + currentItemSurveyorSchedule = INDEX_1_SURVEYOR; + result = surveyorCount == 1; + } else if (INDEX_1_SURVEYOR == currentItemSurveyorSchedule || surveyorCount == 2) { + //第一次测量完成 + measureTimes = 1; + + currentAngleHor2 = angleHor; + currentAngleVer2 = angleVer; + currentSlopDistance2 = slopDistance; + currentHorDistance2 = horDistance; + + currentItemSurveyorSchedule = INDEX_2_SURVEYOR; + result = surveyorCount == 2; + } + return result; + } + + public void clearSurveyStateAndPosition() { + clearSurveyState(); + currentItemIndex = -1; + surveyorState = LeftOrRight.left; + } + + @Override + public void clearSurveyState() { + currentItemSurveyorSchedule = INDEX_NEVER_SURVEYOR; + dataCategory = DataCategory.emptyCategory(); + } + + public boolean hasSurveyor1() { + return INDEX_1_SURVEYOR == currentItemSurveyorSchedule || INDEX_2_SURVEYOR == currentItemSurveyorSchedule; + } + + public boolean hasSurveyor2() { + return INDEX_2_SURVEYOR == currentItemSurveyorSchedule; + } + + public void restoreSurveyor1() { + currentItemSurveyorSchedule = INDEX_1_SURVEYOR; + } + + @Override + public boolean ready2Record() { + if (surveyorCount == 1) { + return INDEX_1_SURVEYOR == currentItemSurveyorSchedule; + } else if (surveyorCount == 2) { + return INDEX_2_SURVEYOR == currentItemSurveyorSchedule; + } + return false; + } + + @Override + public int surveyorCount() { + return surveyorCount; + } + + @Override + public int currentIndex() { + return currentItemIndex; + } + + @Override + public void setCurrentIndex(int currentItemIndex) { + this.currentItemIndex = currentItemIndex; + } + + @Override + public LeftOrRight leftOrRight() { + return surveyorState; + } + + @Override + public void setLeftOrRight(LeftOrRight surveyorState) { + this.surveyorState = surveyorState; + } + + @Override + public int currentCycleIndex() { + return currentCycleIndex; + } + + @Override + public void changeCycleIndex(int cycleIndex) { + this.currentCycleIndex = cycleIndex; + } + + @Override + public DataCategory dataCategory() { + return dataCategory; + } + + @Override + public void setDataCategory(DataCategory dataCategory) { + this.dataCategory = dataCategory; + } + + @Override + public int getMeasureTimes() { + return measureTimes; + } + + @Override + public void setMeasureTimes(int times) { + measureTimes = times; + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/AutoSurveyorMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/AutoSurveyorMethod.java new file mode 100644 index 0000000..c30fe18 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/AutoSurveyorMethod.java @@ -0,0 +1,276 @@ +package com.bingce.controlnetwork.surveyor.method; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.learn.LearnBaseDataRecord; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.App; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.IStationPointRecordCollect; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.coordlib.model.Coordinate; +import com.bingce.totalstation.ControlSurveyData; +import com.bingce.totalstation.ControlSurveyResult; +import com.bingce.totalstation.util.TsUtil; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import blankj.utilcode.util.Utils; +import rxhttp.wrapper.annotations.NonNull; + +public class AutoSurveyorMethod { + public static ControlSurveyResult checkAutoSurveyorInSingleCycle( + boolean autoClosed, String stationId, double instrumentHeight, + Coordinate stationBasePoint, int cycleIndex, int cycleCount, IPrismDelegate prismDelegate, + ICachedData cachedData, IStationPointRecordCollect pointRecordCollect) { + + List controlSurveyData = collectSurveyData(autoClosed, stationId, cycleIndex, cycleCount, + prismDelegate, cachedData, pointRecordCollect); + + return TsUtil.calcMotorStation( + stationBasePoint, + instrumentHeight, + controlSurveyData, + ((App) Utils.getApp()).isCompletedLearn); + } + + public static List collectSurveyData( + boolean autoClosed, String stationId, int cycleIndex, int cycleCount, + IPrismDelegate prismDelegate, + ICachedData cachedData, + IStationPointRecordCollect pointRecordCollect) { + return collectSurveyData(autoClosed, stationId, cycleIndex, cycleCount, prismDelegate, cachedData, null, pointRecordCollect); + } + + public static List collectSurveyData( + boolean autoClosed, String stationId, int currentCycleIndex, int cycleCount, + IPrismDelegate prismDelegate, + ICachedData cachedData, + ISurveyorData surveyorData, + IStationPointRecordCollect pointRecordCollect) { + + int originPointCount = cachedData.pointCount(); + if (autoClosed) { + originPointCount--; + } + List controlSurveyDataList = new ArrayList<>(); + for (int index = 0; index < originPointCount; index++) { + //先获取当前测回 + ControlSurveyData controlSurveyData = getControlSurveyData(cachedData, surveyorData, + pointRecordCollect, prismDelegate, stationId, currentCycleIndex, index); + + if (controlSurveyData != null && !controlSurveyData.isMeasured() && cycleCount > 1) { + for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { + if (currentCycleIndex == cycleIndex) { + continue; + } + + if (cycleIndex % 2 == 1) { + //排除偶测回 + continue; + } + + controlSurveyData = getControlSurveyData(cachedData, surveyorData, + pointRecordCollect, prismDelegate, stationId, cycleIndex, index); + + if (controlSurveyData != null && controlSurveyData.isMeasured()) { + break; + } + } + } + + if (controlSurveyData != null) { + controlSurveyDataList.add(controlSurveyData); + } + + } + return controlSurveyDataList; + } + + + public interface IPrismDelegate { + double prismOf(String originPointId); + } + + + private static ControlSurveyData getControlSurveyData(ICachedData cachedData, ISurveyorData surveyorData, + IStationPointRecordCollect pointRecordCollect, + IPrismDelegate prismDelegate, String stationId, + int cycleIndex, int index) { + + PointRecord pointRecord = pointRecordCollect.pointRecord(cycleIndex, index); + if (pointRecord == null) { + return null; + } + + if (cachedData.isAbandonPoint(cycleIndex, index)) { + return null; + } + + String originPointId = pointRecord.getId(); + String recordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, originPointId, LeftOrRight.left); + DataCategory dataCategory = cachedData.valueState(recordId); + + boolean measured = dataCategory == DataCategory.dirtyAndSurveyed || dataCategory == DataCategory.normalCategory(); + + if (!measured && surveyorData != null) {//如果cached中没有数据,检测surveyData + if (index == surveyorData.currentIndex()) { + if (surveyorData.ready2Record()) { + measured = true; + } + } + } + + Coordinate target = null; + if (PointRecord.TYPE_KNOWN_POINT.equals(pointRecord.getPointType())) { + target = new Coordinate(pointRecord.getX(), pointRecord.getY(), pointRecord.getZ()); + } + double hAngle = 0; + double vAngle = 0; + double distanceSlop = 0; + if (measured) { + if (surveyorData != null && surveyorData.currentIndex() == index) { + hAngle = surveyorData.getAngleHor(); + vAngle = surveyorData.getAngleVer(); + distanceSlop = surveyorData.getSlopDistance(); + } else { + hAngle = cachedData.angleHor(recordId); + vAngle = cachedData.angleVer(recordId); + distanceSlop = cachedData.distanceSlop(recordId); + } + } + double prismHeight = prismDelegate.prismOf(originPointId); + + return new ControlSurveyData( + measured, originPointId, target, + hAngle, vAngle, distanceSlop, prismHeight); + + } + + public static void getWaitLearnDataList(int measureWhat, String stationId, ICachedData cachedData, IStationPointRecordCollect pointRecordCollect + , CallBackWaiteLearnData callBackWaiteLearnData) { + + ThreadPoolUtil.execute(() -> { + List waitLeanDataList = new ArrayList<>(); + + for (int pointIndex = 0; pointIndex < cachedData.realPointCount(); pointIndex++) { + + if (cachedData.isAbandonPoint(0, pointIndex)) { + continue; + } + //测点坐标 + Coordinate target = null; + PointRecord pointRecord = pointRecordCollect.pointRecord(0, pointIndex); + if (pointRecord != null && PointRecord.TYPE_KNOWN_POINT.equals(pointRecord.getPointType())) { + target = new Coordinate(pointRecord.getX(), pointRecord.getY(), pointRecord.getZ()); + } + + SurveyorPoint surveyorPoint = cachedData.getSurveyorPoint(0, pointIndex); + + LearnBaseDataRecord learnBaseDataRecord = SurveyorDatabaseFactory.instance.getLearnDataSource().queryByStationPointId(stationId, surveyorPoint.getOriginalPointId()); + + boolean measured = false; + double hAngle = 0, vAngle = 0, distanceSlop = 0; + if (learnBaseDataRecord != null) { + measured = true; + hAngle = learnBaseDataRecord.angleHor; + vAngle = learnBaseDataRecord.angleVer; + distanceSlop = learnBaseDataRecord.distanceSlop; + } + + waitLeanDataList.add(new ControlSurveyData( + measured, surveyorPoint.getOriginalPointId(), target, + hAngle, vAngle, distanceSlop, Double.parseDouble(surveyorPoint.getPrismHeightDeal()))); + } + + if (callBackWaiteLearnData != null) { + callBackWaiteLearnData.result(waitLeanDataList); + } + + }); + } + + private interface CallBackWaiteLearnData { + void result(List list); + } + + public interface CallBackLearnResultCode { + void result(int code); + } + + public interface CallBackCheckDesign { + void result(String result); + } + + public static void checkAndReloadLearnData(@NonNull Map learnDataMap, + int measureWhat, + String stationId, + ICachedData cachedData, + IStationPointRecordCollect stationPointRecordCollect, + double stationInstrument, + PointRecord stationPointRecord, + @NonNull CallBackLearnResultCode callBackLearnResultCode) { + + if (learnDataMap != null && !learnDataMap.isEmpty()) { + callBackLearnResultCode.result(ControlSurveyResult.CODE_SUCCESS); + return; + } + + getWaitLearnDataList(measureWhat, stationId, cachedData, stationPointRecordCollect, waitLearnDataList -> { + //得到 + ControlSurveyResult controlSurveyResult = TsUtil.calcMotorStation( + getStationCoordinate(stationPointRecord), + stationInstrument, + waitLearnDataList, + ((App) Utils.getApp()).isCompletedLearn); + + learnDataMap.clear(); + if (controlSurveyResult.getCode() == ControlSurveyResult.CODE_SUCCESS) { + List controlSurveyDataList = controlSurveyResult.getControlSurveyDataList(); + for (ControlSurveyData controlSurveyData : controlSurveyDataList) { + learnDataMap.put(controlSurveyData.getPointId(), controlSurveyData); + } + } + + //返回学习结果 + callBackLearnResultCode.result(controlSurveyResult.getCode()); + }); + } + + public static void checkDesignData( + int measureWhat, + String stationId, + ICachedData cachedData, + IStationPointRecordCollect stationPointRecordCollect, + double stationInstrument, + PointRecord stationPointRecord, + @NonNull CallBackCheckDesign callBackCheckDesign) { + + getWaitLearnDataList(measureWhat, stationId, cachedData, stationPointRecordCollect, list -> { + + String result = TsUtil.checkDesignAndMeasureValue(getStationCoordinate(stationPointRecord), + stationInstrument, list, ((App) Utils.getApp()).isCompletedLearn); + + ThreadPoolUtil.executeInMain(() -> callBackCheckDesign.result(result)); + }); + } + + private static Coordinate getStationCoordinate(PointRecord stationPointRecord) { + Coordinate stationCoordinate = null; + if (PointRecord.TYPE_KNOWN_POINT.equals(stationPointRecord.getPointType())) { + stationCoordinate = new Coordinate( + stationPointRecord.getX(), + stationPointRecord.getY(), + stationPointRecord.getZ()); + } + return stationCoordinate; + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/AverageValueMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/AverageValueMethod.java new file mode 100644 index 0000000..09468b4 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/AverageValueMethod.java @@ -0,0 +1,156 @@ +package com.bingce.controlnetwork.surveyor.method; + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.surveyor.method.DeviationValueOfRadianMethod; +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.controlnetwork.util.IdUtil; + + +public class AverageValueMethod { + /** + * 读取缓存数据中的某个测点测量数据,这个数据可能是缓存数据,也可能是当前测量数据 + * + * @param type 水平角,垂直角还是距离 + * @param stationId + * @param cycleIndex + * @param pointIndex + * @param surveyorData + * @param cachedData + * @param leftOrRight + * @return + */ + public static CacheResult leftOrRightValue( + SdAngleValueType type, + String stationId, + int cycleIndex, + int pointIndex, + ISurveyorData surveyorData, + int surveyorCycleIndex, + ICachedData cachedData, + LeftOrRight leftOrRight) { + + int surveyorCount = surveyorData.surveyorCount(); + + String pointId = cachedData.pointId(cycleIndex, pointIndex); + String recordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, leftOrRight); + + boolean isCurrentSurveyor = cycleIndex == surveyorCycleIndex && pointIndex == surveyorData.currentIndex(); + + //&& isCurrentSurveyor && + // surveyorData.leftOrRight() == leftOrRight + //itemIndex == surveyorData.currentIndex() + //优先使用当前测量数据 + if (surveyorData.ready2Record() && isCurrentSurveyor && surveyorData.leftOrRight() == leftOrRight) { + return new CacheResult(true, + _surveyorValue(type, surveyorData)); + } else {//如果缓存的有数据,则直接返回缓存数据 + //检测相应数据是否已经缓存 + DataCategory dataCategory = cachedData.valueState(recordId); + if (dataCategory.hasData()) { + return new CacheResult(true, + _cachedValue(type, recordId, surveyorCount, cachedData)); + } + } + return new CacheResult(false, -1); + } + + + public static CacheResult leftOrRightValue( + SdAngleValueType type, + String recordId, + int surveyorCount, + ICachedData cachedData) { + //检测相应数据是否已经缓存 + DataCategory dataCategory = cachedData.valueState(recordId); + if (dataCategory.hasData()) { + return new CacheResult(true, + _cachedValue(type, recordId, surveyorCount, cachedData)); + } + return new CacheResult(false, -1); + } + + /** + * 缓存的测量数据,根据盘左、盘右求出的均值 + * + * @return 如果是角度,返回的是弧度值;如果是距离,返回的单位是米 + */ + public static CacheResult leftAndRightValue( + SdAngleValueType type, String leftRecordId, String rightRecordId, + int surveyorCount, ICachedData cachedDataSource) { + DataCategory leftDataCategory = cachedDataSource.valueState(leftRecordId); + DataCategory rightDataCategory = cachedDataSource.valueState(rightRecordId); + if (!leftDataCategory.isFreshData() || !rightDataCategory.isFreshData()) { + return new CacheResult(false, -1); + } + double left = _cachedValue(type, leftRecordId, surveyorCount, cachedDataSource); + double right = _cachedValue(type, rightRecordId, surveyorCount, cachedDataSource); + + double value = 0; + switch (type) { + case horAngle: + value = DeviationValueOfRadianMethod.averageHorRadianOfLeftAndRight(left, right); + break; + case verAngle: + value = DeviationValueOfRadianMethod.averageVerRadianOfLeftAndRight(left, right); + break; + case distance: + value = DeviationValueOfRadianMethod.averageDistanceOfLeftAndRight(left, right); + break; + } + return new CacheResult(true, value); + } + + private static double _cachedValue(SdAngleValueType type, String recordId, int surveyorCount, + ICachedData cachedData) { + switch (type) { + case horAngle: + return surveyorCount == 1 ? + cachedData.angleHor1(recordId) : + cachedData.angleHor(recordId); + case verAngle: + return surveyorCount == 1 ? + cachedData.angleVer1(recordId) : + cachedData.angleVer(recordId); + case distance: + return surveyorCount == 1 ? + cachedData.distance1(recordId) : + cachedData.distance(recordId); + } + return 0; + } + + /** + * 从测量数据中读取测量值 + * + * @param type 数据类型(水平角、垂直角or斜距) + * @param surveyorData 测量数据对象 + * @return 测量结果 + */ + private static double _surveyorValue(SdAngleValueType type, ISurveyorData surveyorData) { + int surveyorCount = surveyorData.surveyorCount(); + if (surveyorCount == 1) { + switch (type) { + case horAngle: + return surveyorData.getAngleHor1(); + case verAngle: + return surveyorData.getAngleVer1(); + case distance: + return surveyorData.getDistance1(); + } + } else if (surveyorCount == 2) { + switch (type) { + case horAngle: + return surveyorData.getAngleHor(); + case verAngle: + return surveyorData.getAngleVer(); + case distance: + return surveyorData.getDistance(); + } + } + return 0; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/DeviationValueOfRadianMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/DeviationValueOfRadianMethod.java new file mode 100644 index 0000000..f43909d --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/DeviationValueOfRadianMethod.java @@ -0,0 +1,577 @@ +package com.bingce.controlnetwork.surveyor.method; + +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.surveyor.method.RadianMethod; +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlnetwork.surveyor.data.FaultTolerantData; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.controlnetwork.surveyor.state.base.AdjustmentMeasureWhatUtil; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.utils.Util; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import blankj.utilcode.util.ToastUtils; + + +/** + * 角度偏差处理 + *

+ * 需要考虑极限边界的情况 359.9999 ~~~0.000011之类的 + */ +public class DeviationValueOfRadianMethod { + final static double LIMIT = Math.PI / 36;//默认大小超过5就是有问题 + + /** + * 相近二次读数平均值 + *

+ * 前提是两个角度实际值相近,比如359.9999和0.0001视为相近数,其平均值将被视为0 + */ + public static double similarAverage(double v1, double v2) { + double _1_average = (v1 + v2) / 2.0f; + //不能直接返回,需要判断二者差值大小 + double _1_d1 = Math.abs(v1 - _1_average); + double _1_d2 = Math.abs(v2 - _1_average); + if (_1_d1 < LIMIT && _1_d2 < LIMIT) {//误差不超限,返回 + return _1_average; + } + if (v1 > v2) { + v2 += Math.PI * 2; + } else { + v1 += Math.PI * 2; + } + double _2_average = (v1 + v2) / 2.0f; + double _2_d1 = Math.abs(v1 - _2_average); + double _2_d2 = Math.abs(v2 - _2_average); + if (_2_d1 < LIMIT && _2_d2 < LIMIT) {//误差不超限,返回 + return RadianMethod.formatRadian(_2_average); + } + return (v1 + v2) / 2.0f; + } + + public static double similarAverage(List angles) { + //如果是空,直接返回0 + if (angles.isEmpty()) { + return 0; + } + + //处理边界情况,如果列表中存在边界值,就添加一个偏移量,直到所有值都正常为止 + //但是注意,尝试的次数是有限的,如果尝试次数超过10次,就直接返回平均值 + + double offset = Math.PI / 5.001;//36度左右作为每次的偏量 + double offsetAll = 0; + int tryCount = 10;//最多尝试10次,如果还不行,就退出 + while (tryCount >= 0) { + tryCount--; + //检测是否有边界值 + boolean isOk = true; + for (double angle : angles) { + if (angle >= 2 * Math.PI - LIMIT || angle <= LIMIT) { + isOk = false; + break; + } + } + if (!isOk) {//如果有边界值,就添加偏移量,再次循环 + for (int index = 0; index < angles.size(); index++) { + double v = angles.get(index) + offset; + if (v > Math.PI * 2.0) { + v -= Math.PI * 2.0; + } + angles.set(index, v); + } + offsetAll += offset; + continue; + } + //没有边界了,计算平均值,然后减去总偏移量 + //开始计算 + double all = 0; + for (double v : angles) { + all += v; + } + + double v = all / angles.size() - offsetAll; + if (v < 0) { + v += Math.PI * 2.0; + } + return v; + } + //直接计算平均值 + double all = 0; + for (double v : angles) { + all += v; + } + return all / angles.size(); + } + + /** + * 相近角度差值 + *

+ * 和夹角的含义完全不同!!!! + *

+ * 夹角有方向概念,两样的值不同的方向差别很大:359 -> 1 夹角是2,但是1 -> 359夹角是358 + * 但是这里差值不同,求的是误差变化,没有方向概念,不管是359 ->1 还是1 -> 359差值都是2!! + *

+ * 用于计算二次读数差;测回间同方向2c差;半测回归零差; + *

+ * 前提是两个角度实际值相近,比如359.9999和0.0001视为相近数,其差值为0.0002 + * + * @param angle1 读数1 + * @param angle2 读数2 + * @return 弧度值 + */ + public static double similarRadianDiff(double angle1, double angle2) { + //检测二者是否过大 + double d1 = Math.abs(angle1 - angle2); + if (d1 < LIMIT) {//差距在误差内 + return d1; + } + //差距过大,将小值+360 + if (angle1 > angle2) { + angle2 += Math.PI * 2; + } else { + angle1 += Math.PI * 2; + } + double d2 = Math.abs(angle1 - angle2); + if (d2 < LIMIT) {//差距在误差内 + return d2; + } + return Math.min(d1, d2); + } + + /** + * 求夹角 + * 夹角有方向概念,两样的值不同的方向差别很大:359 -> 1 夹角是2,但是1 -> 359夹角是358 + *

+ * 注意需要处理边界两侧的情况 + *

+ * 夹角是有方向的,从from沿顺时针计算 + *

+ * 尤其用于归零值,必须考虑夹角 + * + * @param from 开始处的角度 + * @param to 结束处的角度 + * @return 二者的夹角,结果是2PI以内的正值 + */ + public static double includeAngle(double from, double to) { + return Util.getIncludedAngle(from, to, true); + } + + /** + * 根据盘左、盘右,求出的水平角值 + * + * @param angleLeftRadian 盘左水平角 + * @param angleRightRadian 盘右水平角 + * @return 水平角, 弧度值 + */ + public static double averageHorRadianOfLeftAndRight(double angleLeftRadian, double angleRightRadian) { + //检测是否有某个值位于0左右 + final double GAP = Util.dmsDoubleToRadian(5); + final double OFFSET = Util.dmsDoubleToRadian(20); + + double left = RadianMethod.formatRadian(angleLeftRadian); + double right = RadianMethod.formatRadian(angleRightRadian); + boolean needOffset = false; + if (left >= Math.PI * 2 - GAP || left <= GAP) { + needOffset = true; + } else if (right >= Math.PI * 2 - GAP || right <= GAP) { + needOffset = true; + } + if (needOffset) {//如果位于0左右,添加偏移 + left = RadianMethod.formatRadian(left + OFFSET); + right = RadianMethod.formatRadian(right + OFFSET); + } + //将盘右转到盘左值 + right = RadianMethod.formatRadian(right - Math.PI); + if (needOffset) { + return (left + right) / 2 - OFFSET; + } else { + return (left + right) / 2; + } + } + + /** + * 根据盘左、盘右,求出的垂直角值 + * + * @param angleLeftRadian 盘左垂直角 + * @param angleRightRadian 盘右垂直角 + * @return 垂直角, 弧度值 + */ + public static double averageVerRadianOfLeftAndRight(double angleLeftRadian, double angleRightRadian) { + return (angleRightRadian - angleLeftRadian - Math.PI) / 2.0; + } + + /** + * 根据盘左、盘右,求出的斜距值 + * + * @param distanceLeft 盘左斜距值 + * @param distanceRight 盘右斜距值 + * @return 斜距值 + */ + public static double averageDistanceOfLeftAndRight(double distanceLeft, double distanceRight) { + return (distanceRight + distanceLeft) / 2.0; + } + + /** + * 盘左、盘右 水平角2c值 + * + * @param angleLeftRadian 盘左水平角 + * @param angleRightRadian 盘右水平角 + * @return 水平角2c差 格式弧度 + */ + public static double radianAngleHor2C(double angleLeftRadian, double angleRightRadian) { + //检测是否有某个值位于0左右 + final double GAP = Util.dmsDoubleToRadian(5); + final double OFFSET = Util.dmsDoubleToRadian(20); + + double left = RadianMethod.formatRadian(angleLeftRadian); + double right = RadianMethod.formatRadian(angleRightRadian); + boolean needOffset = false; + if (left >= (Math.PI * 2 - GAP) || left <= GAP) { + needOffset = true; + } else if (right >= (Math.PI * 2 - GAP) || right <= GAP) { + needOffset = true; + } + if (needOffset) {//如果位于0左右,添加偏移 + left = RadianMethod.formatRadian(left + OFFSET); + right = RadianMethod.formatRadian(right + OFFSET); + } + //将盘右转到盘左值 + right = RadianMethod.formatRadian(right - Math.PI); + return left - right; + } + + /** + * 盘左、盘右 垂直角2c值 + * + * @param angleLeftRadian 盘左垂直角 + * @param angleRightRadian 盘右垂直角 + * @return 垂直角2c差 格式弧度 + */ + public static double radianAngleVer2C(double angleLeftRadian, double angleRightRadian) { + return (angleLeftRadian + angleRightRadian - 2.0 * Math.PI) / 2.0; + } + + /** + * 盘左、盘右 斜距2c值 + * + * @param distanceLeft 盘左斜距 + * @param distanceRight 盘右斜距 + * @return 斜距2c差, 单位m + */ + public static double distance2C(double distanceLeft, double distanceRight) { + return Math.abs(distanceLeft - distanceRight); + } + + //某个测回的归零值列表 + + /** + * 记录「水平角」「垂直角」数据的对象 + */ + public static class AngleDistValue { + public final String pointId; + public final String pointName; + public final double horRadian; + public final double verRadian; + public final double distance; + public final String prismHeight; + public final boolean aloneDistance; + public final boolean isMeasureDistanceNot; + public final boolean isMeasureVerNot; + + public AngleDistValue(String realPointId, String pointName, double horRadian, double verRadian, double distance, + String prismHeight, boolean aloneDistance, boolean isMeasureDistanceNot, boolean isMeasureVerNot) { + this.pointId = realPointId; + this.pointName = pointName; + this.horRadian = horRadian; + this.verRadian = verRadian; + this.distance = distance; + this.prismHeight = prismHeight; + this.aloneDistance = aloneDistance; + this.isMeasureDistanceNot = isMeasureDistanceNot; + this.isMeasureVerNot = isMeasureVerNot; + } + } + + /** + * 算的都是「左角」测量方向下的归零值 + *

+ * 在「无自动闭合」情况下,为了兼容「左右角」测量结果,根据pointId将所有测量数据存入map中 + * 根据「左角」测量来检测「测回间同方向值互差」,所有测回的归零值使用「左角」第一个point来做0点 + *

+ * 如果是「自动闭合」情况,则忽略「左右角」测量,直接按照itemIndex依次计算,第个测回的归零值, + * 使用每次循环的itemIndex=0做0点 + */ + public static List zeroValueOfSingleCycleInLeftOrientation( + final int measureWhat, + final String stationId, final int cycleIndex, final int surveyorCount, + final ICachedData cachedDataSource) { + //1.收集数据,包含排序和处理闭合点 + List list = _collectAllSdaRecordInSingleCycle(measureWhat, + stationId, cycleIndex, surveyorCount, cachedDataSource, true); + //2.归零 + return _zero(list); + } + + /** + * 不强制左角方向,按照测量方向,可能是右角方向 + */ + public static List zeroValueOfSingleCycle( + final int measureWhat, + final String stationId, final int cycleIndex, final int surveyorCount, + final ICachedData cachedDataSource) { + //1.收集数据,包含处理闭合点,但是不排序 + List mapI = _collectAllSdaRecordInSingleCycle( + measureWhat, + stationId, cycleIndex, surveyorCount, cachedDataSource, false); + //2.归零 + return _zero(mapI); + } + + /** + * 计算单个测回内各方向水平角、垂直角值和距离值原始测量数据。 + *

+ * 不含闭合点,如果有闭合点,将自动求出和起始点的平均值,放到起始点的位置 + *

+ * 返回的数据顺序是实际的测量顺序,可能是左角,也可能是右角 + * + * @param cycleIndex 测回索引 + * @param forceLeftOrientation 是否强制返回左角有顺序 + * @return 数值列表,包含闭合点 + */ + private static List _collectAllSdaRecordInSingleCycle( + int measureWhat, + String stationId, int cycleIndex, int surveyorCount, + final ICachedData cachedData, boolean forceLeftOrientation) { + int pointCount = cachedData.pointCount(); + + Map values; + if (AdjustmentMeasureWhatUtil.isAdjustAll(measureWhat)) { + values = collectAllData(cachedData, cycleIndex, stationId, surveyorCount); + } else if (AdjustmentMeasureWhatUtil.isAdjustHorAngle(measureWhat)) { + values = collectHorAngleData(cachedData, cycleIndex, stationId, surveyorCount); + } else if (AdjustmentMeasureWhatUtil.isAdjustVerAngle(measureWhat)) { + values = collectVerAngleData(cachedData, cycleIndex, stationId, surveyorCount); + } else { + ToastUtils.showShort("_collectAllSdaRecordInSingleCycle is error"); + throw new RuntimeException(); + } + + //根据第一个点和最后一个点,判断是否开启了闭合 + //如果开启了闭合,需要将闭合点的平均值添加到起始点 + if (values.size() >= 2) { + String firstId = cachedData.pointId(cycleIndex, 0); + String lastId = cachedData.pointId(cycleIndex, pointCount - 1); + if (SurveyorPoint.pointClosedId(firstId).equals(lastId)) { + //移除最后一个,将其值添加到第一个中 + AngleDistValue first = values.get(firstId); + AngleDistValue last = values.get(lastId); + if (last != null && first != null) { + values.put(firstId, + new AngleDistValue( + first.pointId, + first.pointName, + DeviationValueOfRadianMethod.similarAverage(last.horRadian, first.horRadian), + DeviationValueOfRadianMethod.similarAverage(last.verRadian, first.verRadian), + (last.distance + first.distance) / 2f, + first.prismHeight, first.aloneDistance, first.isMeasureDistanceNot, first.isMeasureVerNot) + ); + values.remove(lastId); + } + } + } + + List result = new ArrayList<>(); + //如果强制使用左角方向,需要根据单测回点顺序排序 + if (forceLeftOrientation) { + //这里使用第0测回作为排序依据 + for (int index = 0; index < pointCount; index++) { + String id = cachedData.pointId(0, index); + AngleDistValue value = values.get(id); + //可能存在闭合点,但是如果有闭合点,上面已经取消,所以在map中没有对应值 + if (value != null) { + result.add(value); + } + } + } else {//非强制左角,直接使用map顺序即可 + for (Map.Entry kv : values.entrySet()) { + if (kv.getValue() != null) { + result.add(kv.getValue()); + } + } + } + + return result; + } + + /** + * 对角度、距离列表执行归零操作 + * 不排序,传入的可能是左角测量值,也可能是右角测量值 + * + * @param list 原始值,没有闭合点(闭合点已经被平均到起始点) + * @return 归零后的列表 + */ + private static List _zero(List list) { + List result = new ArrayList<>(); + if (list != null && !list.isEmpty()) { + double horAngle0 = list.get(0).horRadian; + //归零操作 + for (int index = 0; index < list.size(); index++) { + AngleDistValue value = list.get(index); + double horRadian = DeviationValueOfRadianMethod.includeAngle(horAngle0, value.horRadian); + result.add(new AngleDistValue(value.pointId, value.pointName, horRadian, value.verRadian, value.distance, + value.prismHeight, value.aloneDistance, value.isMeasureDistanceNot, value.isMeasureVerNot)); + } + } + return result; + } + + /** + * + */ + private static Map collectAllData(ICachedData cachedData, + int cycleIndex, + String stationId, + int surveyorCount) { + Map values = new LinkedHashMap<>(); + + for (int itemIndex = 0; itemIndex < cachedData.pointCount(); itemIndex++) { + + //如果是跳过就不验证了 + if (cachedData.isAbandonPoint(cycleIndex, itemIndex)) { + continue; + } + + boolean aloneMeasureDistancePoint = cachedData.isAloneMeasureDistancePoint(cycleIndex, itemIndex); + boolean isMeasureDistanceNot = cachedData.isMeasureDistanceNot(cycleIndex, itemIndex); + boolean isMeasureVerNot = cachedData.isMeasureVerNot(cycleIndex, itemIndex); + boolean isWellSteelPoint = cachedData.isWellSteelPoint(cycleIndex, itemIndex); + String pointId = cachedData.pointId(cycleIndex, itemIndex); + String pointName = cachedData.pointName(cycleIndex, itemIndex); + String leftRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + String rightRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right); + String prismHeight = cachedData.getPrismHeight(cycleIndex, itemIndex); + + //水平角 + CacheResult cachedHorAngle = AverageValueMethod.leftAndRightValue(SdAngleValueType.horAngle, + leftRecordId, + rightRecordId, + surveyorCount, + cachedData); + if (!cachedHorAngle.validate) { + continue; + } + //垂直角 + double verAngle = FaultTolerantData.ERROR_VER_ANGLE; + if (!cachedData.isMeasureVerNot(cycleIndex, itemIndex)) { + CacheResult cachedVerValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.verAngle, + leftRecordId, + rightRecordId, + surveyorCount, + cachedData); + if (cachedVerValue.validate) { + verAngle = cachedVerValue.value; + } + } + //距离 + double distance = FaultTolerantData.ERROR_DISTANCE; + if (!(aloneMeasureDistancePoint || isMeasureDistanceNot || isWellSteelPoint)) { + //不是钢丝不是单独测距不测距离 + CacheResult cachedDistanceValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.distance, + leftRecordId, + rightRecordId, + surveyorCount, + cachedData); + if (cachedDistanceValue.validate) { + distance = cachedDistanceValue.value; + } + } + + AngleDistValue value = new AngleDistValue(pointId, pointName, cachedHorAngle.value, verAngle, distance, + prismHeight, aloneMeasureDistancePoint, isMeasureDistanceNot, isMeasureVerNot); + values.put(pointId, value); + } + + return values; + } + + /** + * + */ + private static Map collectHorAngleData(ICachedData cachedData, + int cycleIndex, + String stationId, + int surveyorCount) { + Map values = new LinkedHashMap<>(); + + for (int itemIndex = 0; itemIndex < cachedData.pointCount(); itemIndex++) { + //如果是跳过就不验证了 + if (cachedData.isAbandonPoint(cycleIndex, itemIndex)) { + continue; + } + String pointId = cachedData.pointId(cycleIndex, itemIndex); + String leftRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + String rightRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right); + CacheResult cachedHorAngle = AverageValueMethod.leftAndRightValue(SdAngleValueType.horAngle, + leftRecordId, + rightRecordId, + surveyorCount, + cachedData); + if (!cachedHorAngle.validate) { + continue; + } + String realPointId = cachedData.realPointId(cycleIndex, itemIndex); + String pointName = cachedData.pointName(cycleIndex, itemIndex); + String prismHeight = cachedData.getPrismHeight(cycleIndex, itemIndex); + boolean aloneMeasureDistancePoint = cachedData.isAloneMeasureDistancePoint(cycleIndex, itemIndex); + boolean isMeasureDistanceNot = cachedData.isMeasureDistanceNot(cycleIndex, itemIndex); + boolean isMeasureVerNot = cachedData.isMeasureVerNot(cycleIndex, itemIndex); + AngleDistValue value = new AngleDistValue(realPointId, pointName, cachedHorAngle.value, FaultTolerantData.ERROR_VER_ANGLE, + FaultTolerantData.ERROR_DISTANCE, prismHeight, aloneMeasureDistancePoint, isMeasureDistanceNot, isMeasureVerNot); + values.put(pointId, value); + } + return values; + } + + /** + * + */ + private static Map collectVerAngleData(ICachedData cachedData, + int cycleIndex, + String stationId, + int surveyorCount) { + Map values = new LinkedHashMap<>(); + for (int itemIndex = 0; itemIndex < cachedData.realPointCount(); itemIndex++) { + //如果是跳过就不验证了 + if (cachedData.isAbandonPoint(cycleIndex, itemIndex)) { + continue; + } + String pointId = cachedData.pointId(cycleIndex, itemIndex); + String leftRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + String rightRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right); + + CacheResult cachedVerValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.verAngle, + leftRecordId, + rightRecordId, + surveyorCount, + cachedData); + if (!cachedVerValue.validate) { + continue; + } + String pointName = cachedData.pointName(cycleIndex, itemIndex); + String prismHeight = cachedData.getPrismHeight(cycleIndex, itemIndex); + boolean aloneMeasureDistancePoint = cachedData.isAloneMeasureDistancePoint(cycleIndex, itemIndex); + boolean isMeasureDistanceNot = cachedData.isMeasureDistanceNot(cycleIndex, itemIndex); + boolean isMeasureVerNot = cachedData.isMeasureVerNot(cycleIndex, itemIndex); + AngleDistValue value = new AngleDistValue(pointId, pointName, FaultTolerantData.ERROR_VER_ANGLE, + cachedVerValue.value, FaultTolerantData.ERROR_DISTANCE, prismHeight, aloneMeasureDistancePoint, isMeasureDistanceNot, isMeasureVerNot); + values.put(pointId, value); + } + + return values; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/FindTargetMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/FindTargetMethod.java new file mode 100644 index 0000000..57a3b82 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/FindTargetMethod.java @@ -0,0 +1,181 @@ +package com.bingce.controlnetwork.surveyor.method; + +import androidx.annotation.NonNull; + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.util.IdUtil; + + +/** + * 根据移动方向和条件,查找下一个符合的目标点 + */ +public class FindTargetMethod { + /** + * 从指定位置,在单个测期内,向前或向后查找empty点 + * + * @param cycleIndex 测期 + * @param itemIndex 指定item索引 + * @param surveyorState 测量状态(盘左or盘右) + * @param pointCount 测站中的测点个数(含闭合点) + * @param moveForward 查找方向(向前or向后) + * @param stationSurveyorDataSource 缓存的测站测量数据 + * @return 包含目标位置和测量状态 + */ + public static Target findEmptyTargetInSingleCycle(final String stationId, + final int cycleIndex, + final int itemIndex, + final LeftOrRight surveyorState, + final int pointCount, + final boolean moveForward, + final @NonNull ICachedData stationSurveyorDataSource) { + return findTargetInSingleCycle( + stationId, cycleIndex, itemIndex, surveyorState, pointCount, moveForward, + DataCategory.emptyCategory(), stationSurveyorDataSource); + } + + /** + * 从指定位置,在单个测期内,向前或向后查找empty点 + * + * @param cycleIndex 测期 + * @param itemIndex 指定item索引 + * @param surveyorState 测量状态(盘左or盘右) + * @param pointCount 测站中的测点个数(含闭合点) + * @param moveForward 查找方向(向前or向后) + * @param cachedData 缓存的测站测量数据 + * @return 包含目标位置和测量状态 + */ + public static Target findDirtyTargetInSingleCycle(final String stationId, + final int cycleIndex, + final int itemIndex, + final LeftOrRight surveyorState, + final int pointCount, + final boolean moveForward, + final @NonNull ICachedData cachedData) { + return findTargetInSingleCycle( + stationId, cycleIndex, itemIndex, surveyorState, pointCount, moveForward, + DataCategory.needResurvey(), cachedData); + } + + /** + * 从指定位置,在单个测期内,向前或向后查找待测点 + * + * @param cycleIndex 测期 + * @param itemIndex 指定item索引 + * @param leftOrRight 测量状态(盘左or盘右) + * @param pointCount 测站中的测点个数(含闭合点) + * @param moveForward 查找方向(向前or向后) + * @param dataCategory 要查找的数据类型 + * @param cachedData 缓存的测站测量数据 + * @return 包含目标位置和测量状态 + */ + public static Target findTargetInSingleCycle(final String stationId, + final int cycleIndex, + final int itemIndex, + final LeftOrRight leftOrRight, + final int pointCount, + final boolean moveForward, + final DataCategory dataCategory, + final @NonNull ICachedData cachedData) { + int targetIndex = itemIndex; + LeftOrRight targetLeftOrRight = leftOrRight; + boolean findTarget = false; + while (true) { + //检测当前遍历到的状态是否完成测量 + if (checkDataCategory(stationId, cycleIndex, targetIndex, targetLeftOrRight, dataCategory, cachedData)) { + //如果找到没有测量的位置,则停止查找 + findTarget = true; + break; + } + if (moveForward) { + //向后移动,查找 + if (LeftOrRight.left == targetLeftOrRight) {//测量盘左 + if (targetIndex == pointCount - 1) {//转到测量盘右 + targetLeftOrRight = LeftOrRight.right; + } else { + targetIndex = targetIndex + 1; + targetLeftOrRight = LeftOrRight.left; + } + } else if (LeftOrRight.right == targetLeftOrRight) {//测量盘右 + if (targetIndex <= 0) {//本测期已经完成,则判断 + break; + } else { + targetIndex = targetIndex - 1; + targetLeftOrRight = LeftOrRight.right; + } + } else { + break; + } + } else { + //向前移动,查找 + if (LeftOrRight.right == targetLeftOrRight) {//测量盘右 + if (targetIndex == pointCount - 1) {//转到测量盘右 + targetLeftOrRight = LeftOrRight.left; + } else { + targetIndex = targetIndex + 1; + targetLeftOrRight = LeftOrRight.right; + } + } else if (LeftOrRight.left == targetLeftOrRight) {//测量盘左 + if (targetIndex <= 0) {//本测期已经完成,则判断 + break; + } else { + targetIndex = targetIndex - 1; + targetLeftOrRight = LeftOrRight.left; + } + } else { + break; + } + } + } + //处理回调 + if (findTarget) { + return new Target(cycleIndex, targetIndex, targetLeftOrRight); + } else { + return null; + } + } + + public static class Target { + public final int cycleIndex; + public final int itemIndex; + public final LeftOrRight leftOrRight; + + Target(int cycleIndex, int itemIndex, LeftOrRight leftOrRight) { + this.cycleIndex = cycleIndex; + this.itemIndex = itemIndex; + this.leftOrRight = leftOrRight; + } + } + + /** + * 检测目标处测量状态 + * + * @param cycleIndex 测期 + * @param itemIndex 测点索引 + * @param surveyorState 测量状态 + * @param cachedData 测站数据 + * @return 是否通过检测 + */ + private static boolean checkDataCategory(final String stationId, int cycleIndex, int itemIndex, + LeftOrRight surveyorState, + final DataCategory targetCategory, + ICachedData cachedData) { + if (cachedData.isAbandonPoint(cycleIndex, itemIndex)) { + return false; + } + + String pointId = cachedData.pointId(cycleIndex, itemIndex); + if (LeftOrRight.left == surveyorState) { + String leftKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + DataCategory dataCategory = cachedData.valueState(leftKey); + return dataCategory == targetCategory; + } else if (LeftOrRight.right == surveyorState) { + String rightKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right); + DataCategory dataCategory = cachedData.valueState(rightKey); + return dataCategory == targetCategory; + } + return false; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleCheckMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleCheckMethod.java new file mode 100644 index 0000000..867bb26 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleCheckMethod.java @@ -0,0 +1,147 @@ +package com.bingce.controlnetwork.surveyor.method; + +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.controlnetwork.surveyor.state.base.CheckToleranceUtil; +import com.bingce.utils.Util; + +import java.util.ArrayList; +import java.util.List; + +public class SingleCycleCheckMethod { + + /** + * 检测测回内2c互差 + * + * @param hor2cDiff 水平角2c互差限制 + * @param ver2cDiff 垂直角i互差限制 + * @return 错误信息 为空则无错 + */ + public static String check(int measureWhat, double hor2cDiff, double ver2cDiff, + String stationId, + int cycleIndex, + ISurveyorData surveyorData, + ICycleRecorder cycleRecorder, + ICachedData cachedData) { + int pointCount = cachedData.pointCount(); + + List horErrorList = new ArrayList<>(); + if (CheckToleranceUtil.checkAngleHor(measureWhat)) { + //检测 「测回内不同方向2c互差」 + for (int i = 0; i < pointCount; i++) { + boolean abandonI = cachedData.isAbandonPoint(cycleIndex, i); + if (abandonI) { + continue; + } + + for (int j = i + 1; j < pointCount; j++) { + boolean abandonJ = cachedData.isAbandonPoint(cycleIndex, j); + if (abandonJ) { + continue; + } + + CacheResult i2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.horAngle, + stationId, cycleIndex, i, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); + CacheResult j2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.horAngle, + stationId, cycleIndex, j, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); + + double absHor = Math.abs(i2C.value - j2C.value); + if (!j2C.validate || !i2C.validate || hor2cDiff < absHor) { + //没有通过检测 + horErrorList.add(new Item(i, j, absHor)); + } + } + } + } + + List verErrorList = new ArrayList<>(); + if (CheckToleranceUtil.checkAngleVer(measureWhat)) { + //检测 「测回内不同方向i互差」 + for (int i = 0; i < pointCount; i++) { + if (CheckToleranceUtil.isIgnoreVerPoint(cachedData, cycleIndex, i)) { + continue; + } + for (int j = i + 1; j < pointCount; j++) { + if (CheckToleranceUtil.isIgnoreVerPoint(cachedData, cycleIndex, j)) { + continue; + } + + CacheResult i2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, + stationId, cycleIndex, i, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); + CacheResult j2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, + stationId, cycleIndex, j, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); + double absVer = Math.abs(i2C.value - j2C.value); + if (!j2C.validate || !i2C.validate || ver2cDiff < absVer) { + //没有通过检测 + verErrorList.add(new Item(i, j, absVer)); + } + } + } + } + + return errorString(hor2cDiff, ver2cDiff, cycleIndex, + horErrorList, verErrorList, cachedData); + } + + private static String errorString(double horLimit, double verLimit, int cycleIndex, + List horErrorList, List verErrorList, + ICachedData cachedDataSource) { + if (horErrorList.isEmpty() && verErrorList.isEmpty()) { + return null; + } + StringBuilder stringBuilder = new StringBuilder(); + if (!horErrorList.isEmpty()) { + stringBuilder.append("测回内不同方向2c互差超限(") + .append("限差:") + .append(horLimit) + .append("'')\n"); + for (Item item : horErrorList) { + String point1 = cachedDataSource.pointName(cycleIndex, item.item1); + String point2 = cachedDataSource.pointName(cycleIndex, item.item2); + stringBuilder + .append(" |") + .append(point1) + .append(" - ") + .append(point2) + .append("|=") + .append(Util.formatDouble2String(item.difference, 1)) + .append("\n"); + } + } + if (!verErrorList.isEmpty()) { + stringBuilder.append("测回内不同方向i互差超限(") + .append("限差:") + .append(verLimit) + .append("'')\n"); + for (Item item : verErrorList) { + String point1 = cachedDataSource.pointName(cycleIndex, item.item1); + String point2 = cachedDataSource.pointName(cycleIndex, item.item2); + stringBuilder + .append(" |") + .append(point1) + .append(" - ") + .append(point2) + .append("|=") + .append(Util.formatDouble2String(item.difference, 1)) + .append("\n"); + } + } + + return stringBuilder.toString(); + } + + private static class Item { + final int item1; + final int item2; + final double difference; + + public Item(int item1, int item2, double difference) { + this.item1 = item1; + this.item2 = item2; + this.difference = difference; + } + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleTipsMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleTipsMethod.java index 6d87248..57f5b42 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleTipsMethod.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SingleCycleTipsMethod.java @@ -10,15 +10,13 @@ import com.bingce.controlapphelper.datasource.database.point.PointRecord; import com.bingce.controlapphelper.datasource.database.surveyorstation.ISurveyorStationDataSource; import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; -import com.bingce.controlapphelper.surveyor.method.model.IStateDelegate; -import com.bingce.controlapphelper.util.Tools; import com.bingce.controlnetwork.fragment.SelectReSurveyorPointFragment; +import com.bingce.controlnetwork.surveyor.method.model.IStateDelegate; import com.bingce.utils.ThreadPoolUtil; import java.util.ArrayList; import java.util.List; -import com.bingce.controlnetwork.R; public class SingleCycleTipsMethod { /* @@ -29,8 +27,8 @@ public class SingleCycleTipsMethod { FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { //取消 delegate.onOptionTips(msg, - Tools.getString(R.string.retest_direction), - Tools.getString(R.string.retest_cycle), + "重测方向", + "重测本测回", () -> {//选择重测方向 ThreadPoolUtil.execute(() -> reSurveyorPoint(stationId, delegate, fragmentManager, lifecycleOwner)); @@ -87,7 +85,7 @@ public class SingleCycleTipsMethod { private static void reSurveyorCycle(String msg, String stationId, int currentCycleIndex, IStateDelegate delegate, FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { - delegate.onOptionTips(Tools.getString(R.string.tips_delete_current_cycle_surveyor_record), + delegate.onOptionTips("是否确定删除该测回所有数据?", null, null, () -> { delegate.deleteSingleCycleData(currentCycleIndex); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SurveyorAdjustMethodTj.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SurveyorAdjustMethodTj.java new file mode 100644 index 0000000..c93ea86 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/SurveyorAdjustMethodTj.java @@ -0,0 +1,642 @@ +package com.bingce.controlnetwork.surveyor.method; + + +import android.os.Parcel; +import android.os.Parcelable; +import android.text.TextUtils; + +import androidx.annotation.WorkerThread; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.alonedistance.IAloneDistanceRecordDataSource; +import com.bingce.controlapphelper.datasource.database.alonedistance.WellDistance; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.project.IProjectDataSource; +import com.bingce.controlapphelper.datasource.database.project.ProjectRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.IToleranceDetailDataSource; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.surveyor.method.RadianMethod; +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.model.AloneAdjustItem; +import com.bingce.controlnetwork.surveyor.data.FaultTolerantData; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.base.CheckToleranceUtil; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.utils.Util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import blankj.utilcode.util.ToastUtils; + +public class SurveyorAdjustMethodTj { + private final static int ERROR_CODE_LEFT_RIGHT_COUNT_NOT_EQUAL = 1; + private final static int ERROR_CODE_ZERO_VALUE_COUNT_NOT_EQUAL = ERROR_CODE_LEFT_RIGHT_COUNT_NOT_EQUAL + 1; + + @WorkerThread + public static AdjustResult calStationAdjust(int measureWhat, SurveyorStationRecord stationRecord, ICachedData cachedData) { + if (stationRecord == null) { + return new AdjustResult("测站数据为空"); + } + //2.读取项目数据 + IProjectDataSource projectDataSource = + SurveyorDatabaseFactory.instance.getProjectDataSource(); + ProjectRecord projectRecord = projectDataSource.getRecord(stationRecord.projectId); + if (projectRecord == null) { + return new AdjustResult("项目数据为空"); + } + //3.读取限差数据 + IToleranceDetailDataSource toleranceDetailDataSource = + SurveyorDatabaseFactory.instance.getToleranceDetailDataSource(); + ToleranceDetailRecord toleranceDetailRecordTj = + toleranceDetailDataSource.getRecordSync(projectRecord.getToleranceId()); + if (toleranceDetailRecordTj == null) { + return new AdjustResult("限差参数为空"); + } + //4.测量次数,测回数 + int surveyorCount = toleranceDetailRecordTj.getSurveyorCount(); + int cycleCount = StationUtilPla.getCycleCount(measureWhat, stationRecord, toleranceDetailRecordTj); + boolean leftRightSurveyor = stationRecord.isLeftAndRightSurveyor();//左右角测量 + //5.如果是左右角测量,判断是否超限 + if (CheckToleranceUtil.checkAngleHor(measureWhat) + && leftRightSurveyor) { + //获取单测回归零值 + int leftCycleCount = 0;//左角测量时测回个数 + List leftZeroes = new ArrayList<>();//左角归零值 + int rightCycleCount = 0;//右角测量时测回个数 + List rightZeroes = new ArrayList<>();//右角归零值 + for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { + List values = + DeviationValueOfRadianMethod.zeroValueOfSingleCycle(measureWhat, stationRecord.getId(), cycleIndex, surveyorCount, cachedData); + if (cycleIndex % 2 == 0) {//左角归零 + leftCycleCount++; + if (leftZeroes.isEmpty()) { + for (DeviationValueOfRadianMethod.AngleDistValue value : values) { + leftZeroes.add(value.horRadian); + } + } else { + for (int index = 0; index < values.size(); index++) { + if (index >= leftZeroes.size()) { + continue; + } + leftZeroes.set(index, leftZeroes.get(index) + values.get(index).horRadian); + } + } + } else {//右角归零 + rightCycleCount++; + if (rightZeroes.isEmpty()) { + for (DeviationValueOfRadianMethod.AngleDistValue value : values) { + rightZeroes.add(value.horRadian); + } + } else { + for (int index = 0; index < values.size(); index++) { + if (index >= rightZeroes.size()) { + continue; + } + rightZeroes.set(index, rightZeroes.get(index) + values.get(index).horRadian); + } + } + } + } + //求左右角归零平均值 + for (int index = 0; index < leftZeroes.size(); index++) { + leftZeroes.set(index, leftZeroes.get(index) / leftCycleCount); + } + for (int index = 0; index < rightZeroes.size(); index++) { + rightZeroes.set(index, rightZeroes.get(index) / rightCycleCount); + } + + if (leftZeroes.size() != rightZeroes.size()) { + //左右角归零值个数不一样,计算错误 + return new AdjustResult("计算错误(错误码" + ERROR_CODE_LEFT_RIGHT_COUNT_NOT_EQUAL + ")"); + } + //检测左右角之和是否超限 + final double TOP = Util.dmsDoubleToRadian(0.0004); + final double BOTTOM = 2 * Math.PI - TOP; + for (int index = 0; index < leftZeroes.size(); index++) { + double leftAngle = leftZeroes.get(index); + double rightAngle = rightZeroes.get(index); + double resultAngle = RadianMethod.formatRadian(leftAngle + rightAngle); + if (resultAngle < BOTTOM && resultAngle > TOP) { + return new AdjustResult("左右角之和超限!"); + } + } + } + //6.左右角之和通过检测,则转为左角计算整体归零值 + List<_VD> vds = new ArrayList<>(); + Map> cycle2Zeroes = new HashMap<>(); + for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { + List values = + DeviationValueOfRadianMethod.zeroValueOfSingleCycleInLeftOrientation( + measureWhat, stationRecord.getId(), cycleIndex, surveyorCount, cachedData); + + List horZeroes = new ArrayList<>(); + for (DeviationValueOfRadianMethod.AngleDistValue value : values) { + horZeroes.add(value.horRadian); + } + cycle2Zeroes.put(cycleIndex, horZeroes); + + if (vds.isEmpty()) { + for (DeviationValueOfRadianMethod.AngleDistValue v : values) { + vds.add(new _VD(v.pointId, v.pointName, v.verRadian, v.distance, v.prismHeight, v.aloneDistance, v.isMeasureDistanceNot, v.isMeasureVerNot)); + } + } else { + for (int index = 0; index < values.size(); index++) { + if (vds.size() <= index) { + return new AdjustResult("计算错误(错误码" + ERROR_CODE_ZERO_VALUE_COUNT_NOT_EQUAL + ")"); + } + _VD hvd = vds.get(index); + DeviationValueOfRadianMethod.AngleDistValue angleDistValue = values.get(index); +// hvd.hor = DeviationValueOfRadianMethod.similarAverage(hvd.hor, angleDistValue.horRadian); + + if (angleDistValue.verRadian != FaultTolerantData.ERROR_VER_ANGLE) { + hvd.ver += angleDistValue.verRadian; + } else { + hvd.ver = FaultTolerantData.ERROR_VER_ANGLE; + } + + hvd.distance += angleDistValue.distance; + } + } + } + + //水平角的归零值要特殊处理 + //先计算结点数量,取最小值 + int minPointSize = Integer.MAX_VALUE; + for (Map.Entry> entry : cycle2Zeroes.entrySet()) { + minPointSize = Math.min(minPointSize, entry.getValue() == null ? 0 : entry.getValue().size()); + } + + List zeros = new ArrayList<>(); + if (minPointSize > 0) { + for (int pointIndex = 0; pointIndex < minPointSize; pointIndex++) { + List doubles = new ArrayList<>(); + for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { + List zeroList = cycle2Zeroes.get(cycleIndex); + if (zeroList == null) { + break; + } + if (zeroList.size() <= pointIndex) { + break; + } + doubles.add(zeroList.get(pointIndex)); + } + + //计算平均值 + double average = DeviationValueOfRadianMethod.similarAverage(doubles); + + zeros.add(average); + } + } + + //7.求归零平均值 + ArrayList result = new ArrayList<>(); + for (int pointIndex = 0; pointIndex < vds.size(); pointIndex++) { + _VD hvd = vds.get(pointIndex); + Item item = new Item( + hvd.pointId, + hvd.pointName, + zeros.size() <= pointIndex ? 0 : zeros.get(pointIndex), + getFinalAdjustVerAngle(hvd.ver, cycleCount), +// getFinalAdjustDistance(stationRecord.getAdditionConstantActual(), stationRecord.getMultiplyingConstantActual(), hvd.distance / cycleCount), + hvd.distance / cycleCount, + hvd.prismHeight, hvd.aloneDistance, hvd.isMeasureDistanceNot, hvd.isMeasureVerNot); + result.add(item); + } + + return new AdjustResult(result); + } + + private static double getFinalAdjustVerAngle(double hdvVer, int cycleCount) { + if (hdvVer == FaultTolerantData.ERROR_VER_ANGLE) { + return hdvVer; + } + return hdvVer / cycleCount; + } + + private static double getFinalAdjustDistance(double a, double b, double distance) { + return Tools.getAmendDistance(a, b, 0, distance); + } + + public static class AdjustResult { + public ArrayList result; + public String errorString; + + public AdjustResult() { + } + + public AdjustResult(ArrayList result) { + this.result = result; + errorString = ""; + } + + public AdjustResult(String errorString) { + this.result = null; + this.errorString = errorString; + } + + public void setErrorString(String errorString) { + this.errorString = errorString; + } + + public void setResult(ArrayList result) { + this.result = result; + } + } + + /** + * 临时变量,保存 水平、垂直、和距离 + */ + private static class _VD { + final String pointId; + final String pointName; + double ver; + double distance; + String prismHeight; + boolean aloneDistance; + boolean isMeasureDistanceNot; + boolean isMeasureVerNot; + + + _VD(String pointId, String pointName, double v, double d, String prismHeight, + boolean aloneDistance, boolean isMeasureDistanceNot, boolean isMeasureVerNot) { + this.pointId = pointId; + this.pointName = pointName; + this.ver = v; + this.distance = d; + this.prismHeight = prismHeight; + this.aloneDistance = aloneDistance; + this.isMeasureDistanceNot = isMeasureDistanceNot; + this.isMeasureVerNot = isMeasureVerNot; + } + } + + public static class Item implements Parcelable { + private String pointId; + private String pointName; + private double horAngle; + private double verAngle; + private double distance; + private String prismHeight; + + protected boolean aloneDistance; + protected boolean isMeasureDistanceNot; + protected boolean isMeasureVerNot; + + public Item() { + } + + public Item(String pointId, String pointName, double horAngle, double verAngle, double distance, + String prismHeight, boolean aloneDistance, boolean isMeasureDistanceNot, boolean isMeasureVerNot) { + this.pointId = pointId; + this.pointName = pointName; + this.horAngle = horAngle; + this.verAngle = verAngle; + this.distance = distance; + this.prismHeight = prismHeight; + this.aloneDistance = aloneDistance; + this.isMeasureDistanceNot = isMeasureDistanceNot; + this.isMeasureVerNot = isMeasureVerNot; + } + + public String getPointId() { + return pointId; + } + + public String getPointName() { + return pointName; + } + + + public double getHorAngle() { + return horAngle; + } + + public void setHorAngle(double horAngle) { + this.horAngle = horAngle; + } + + public double getVerAngle() { + return verAngle; + } + + + public double getDistance() { + return distance; + } + + + public String getPrismHeight() { + return prismHeight; + } + + public String getPrismHeightActual() { + if (TextUtils.isEmpty(prismHeight)) { + return "0"; + } + return prismHeight; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.pointId); + dest.writeString(this.pointName); + dest.writeDouble(this.horAngle); + dest.writeDouble(this.verAngle); + dest.writeDouble(this.distance); + dest.writeString(this.prismHeight); + dest.writeByte(this.aloneDistance ? (byte) 1 : (byte) 0); + } + + public void readFromParcel(Parcel source) { + this.pointId = source.readString(); + this.pointName = source.readString(); + this.horAngle = source.readDouble(); + this.verAngle = source.readDouble(); + this.distance = source.readDouble(); + this.prismHeight = source.readString(); + this.aloneDistance = source.readByte() != 0; + } + + protected Item(Parcel in) { + this.pointId = in.readString(); + this.pointName = in.readString(); + this.horAngle = in.readDouble(); + this.verAngle = in.readDouble(); + this.distance = in.readDouble(); + this.prismHeight = in.readString(); + this.aloneDistance = in.readByte() != 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public Item createFromParcel(Parcel source) { + return new Item(source); + } + + @Override + public Item[] newArray(int size) { + return new Item[size]; + } + }; + } + + /** + * @param stationId + * @param cachedData + * @param isExcludeEveryPointError true 包含每个点的错误信息 + * @return 分开观测垂直角平差 + */ + @WorkerThread + public static List calAloneVer(String stationId, ICachedData cachedData, boolean isExcludeEveryPointError) { + List resultAdjustList = new ArrayList<>(); + + if (cachedData == null || cachedData.realPointCount() == 0) + return resultAdjustList; + + //1.读取测站数据 + SurveyorStationRecord stationRecord = SurveyorDatabaseFactory.instance.getSurveyorStation().getRecordSync(stationId); + if (stationRecord == null) { + ToastUtils.showShort("测站数据为空"); + return resultAdjustList; + } + //2.读取项目数据 + ProjectRecord projectRecord = SurveyorDatabaseFactory.instance.getProjectDataSource().getRecord(stationRecord.projectId); + if (projectRecord == null) { + ToastUtils.showShort("项目数据为空"); + return resultAdjustList; + } + //3.读取限差数据 + ToleranceDetailRecord toleranceDetailRecordTj = SurveyorDatabaseFactory.instance.getToleranceDetailDataSource().getRecordSync(projectRecord.getToleranceId()); + if (toleranceDetailRecordTj == null) { + ToastUtils.showShort("限差参数为空"); + return resultAdjustList; + } + + int cycleCount = StationUtilPla.getCycleCount(StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER, stationRecord, toleranceDetailRecordTj); + int surveyorCount = toleranceDetailRecordTj.getSurveyorCount(); + //遍历所有点 + for (int pointIndex = 0; pointIndex < cachedData.realPointCount(); pointIndex++) { + //从1开始循环 + SurveyorPoint point = cachedData.getSurveyorPoint(0, pointIndex); + String prismHeight = point.getPrismHeight(); + String pointId = point.getOriginalPointId(); + PointRecord pointRecord = SurveyorDatabaseFactory.instance.getPointDataSource().findByIdSync(pointId); + String pointName = pointRecord.name; + + int verCalCount = 0; + double verSum = 0; + int errorCycleIndex = -1; + for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { + String leftRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + String rightRecordId = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right); + + CacheResult cachedVerValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.verAngle, + leftRecordId, + rightRecordId, + surveyorCount, + cachedData); + + if (!cachedVerValue.validate) { + //点有个测回数据出问题 + errorCycleIndex = cycleIndex; + break; + } + + verSum += cachedVerValue.value; + verCalCount++; + } + + if (errorCycleIndex == -1) { + resultAdjustList.add(new AloneAdjustItem(pointId, pointName, 0, verSum / verCalCount, + 0, prismHeight, + false, false, false, + null)); + } else { + //当前点平差异常 + if (isExcludeEveryPointError) { + resultAdjustList.add(new AloneAdjustItem(pointId, pointName, 0, 0, + 0, prismHeight, + false, false, false, + "第" + (errorCycleIndex + 1) + "测回数据异常")); + } + } + } + + return resultAdjustList; + } + + + /** + * @param stationId + * @param cachedData + * @param isExcludeEveryPointError true 包含每个点的错误信息 + * @return 单独测距平差数据 + */ + @WorkerThread + public static List calAloneDistance(String stationId, ICachedData cachedData, boolean isExcludeEveryPointError) { + List resultAdjustList = new ArrayList<>(); + if (cachedData == null || cachedData.realPointCount() == 0) + return resultAdjustList; + //1.读取测站数据 + SurveyorStationRecord stationRecord = SurveyorDatabaseFactory.instance.getSurveyorStation().getRecordSync(stationId); + if (stationRecord == null) { + ToastUtils.showShort("测站数据为空"); + return resultAdjustList; + } + //2.读取项目数据 + ProjectRecord projectRecord = SurveyorDatabaseFactory.instance.getProjectDataSource().getRecord(stationRecord.projectId); + if (projectRecord == null) { + ToastUtils.showShort("项目数据为空"); + return resultAdjustList; + } + //3.读取限差数据 + ToleranceDetailRecord toleranceDetailRecordTj = SurveyorDatabaseFactory.instance.getToleranceDetailDataSource().getRecordSync(projectRecord.getToleranceId()); + if (toleranceDetailRecordTj == null) { + ToastUtils.showShort("限差参数为空"); + return resultAdjustList; + } + //4.测量次数,测回数 + int cycleCount = ToleranceDetailRecord.ALONE_DISTANCE_CYCLE_COUNT; + int surveyorCount = ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT; + + //遍历所有点 + for (int i = 0; i < cachedData.realPointCount(); i++) { + //从1开始循环 + SurveyorPoint point = cachedData.getSurveyorPoint(0, i); + + String prismHeight = point.getPrismHeight(); + String pointId = point.getOriginalPointId(); + PointRecord pointRecord = SurveyorDatabaseFactory.instance.getPointDataSource().findByIdSync(pointId); + String pointName = pointRecord.name; + + IAloneDistanceRecordDataSource wellDistanceDataSource = SurveyorDatabaseFactory.instance.getAloneDistanceRecordDataSource(); + AloneDistanceRecord wellRecord = wellDistanceDataSource.getRecordSync(stationId, 0, point.getOriginalPointId()); + if (AloneDistanceRecord.isCompleteSurveyorNot(wellRecord)) { + if (isExcludeEveryPointError) { + resultAdjustList.add(new AloneAdjustItem(pointId, pointName, 0, 0, 0, prismHeight, + true, false, false, + "观测数据不完整")); + } + continue; + } + + //测量原始数据 + List distanceValues = wellRecord.distanceValues; +// //获取测点的气象修正方式 +// SurveyorPointScheduleRecord lastSurveyorPointSchedule = TjDbFactory.instance.getSurveyorPointScheduleDataSource().getLastSurveyorPointSchedule(stationId, pointId); +// +// if (lastSurveyorPointSchedule == null) { +// if (isExcludeEveryPointError) { +// resultAdjustList.add(new AloneAdjustItem(pointId, pointName, 0, 0, 0, prismHeight, +// true, false, false, +// "气象修正参数不完整")); +// } +// continue; +// } +// if (lastSurveyorPointSchedule.isHighPrecision() +// && !SurveyorPointScheduleRecord.checkHighAllWeatherAmendFinish(stationId, pointId, cycleCount)) { +// //判断高精度所有测回是否完 +// if (isExcludeEveryPointError) { +// resultAdjustList.add(new AloneAdjustItem(pointId, pointName, 0, 0, 0, prismHeight, +// true, false, false, +// "气象修正参数不完整")); +// } +// continue; +// } + +// double average = 0; +// for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { +// +// +// double distanceAverageEveryCycle = Tools.calculateCollectionDoubleAverage(distanceValues.subList(cycleIndex * surveyorCount, (cycleIndex + 1) * surveyorCount), projectRecord.isShowSlopDistance()); +//// if (lastSurveyorPointSchedule.isHighPrecision()) { +//// distanceAverageEveryCycle = getHighPrecisionDistance(stationId, cycleIndex, pointId, distanceAverageEveryCycle); +//// } else if (lastSurveyorPointSchedule.isOrdinary()) { +//// distanceAverageEveryCycle = getOrdinaryOrNoAmendDistance(stationId, pointId, SurveyorPointScheduleRecord.AMMEND_TYPE_ORDINARY, distanceAverageEveryCycle); +//// } else { +//// distanceAverageEveryCycle = getOrdinaryOrNoAmendDistance(stationId, pointId, SurveyorPointScheduleRecord.AMMEND_TYPE_NO, distanceAverageEveryCycle); +//// } +// +// average += distanceAverageEveryCycle; +// } + // TODO: 2024/8/30 + resultAdjustList.add(new AloneAdjustItem(pointId, pointName, 0, 0, 1, prismHeight, + true, false, false, + null)); + } + + return resultAdjustList; + } + + /** + * 获取一般修正或不修正的距离 + */ +// public static double getOrdinaryOrNoAmendDistance(String stationId, String pointId, int amendType, double distanceAverageEveryCycle) { +// ISurveyorPointWeatherAmendmentDataSource surveyorPointWeatherAmendmentDataSource = TjDbFactory.instance.getSurveyorPointWeatherAmendmentDataSource(); +// SurveyorPointWeatherAmendmentRecord surveyorWeatherAmendment = surveyorPointWeatherAmendmentDataSource.getSurveyorWeatherAmendmentByStationPointAmendType(stationId, pointId, amendType); +// if (surveyorWeatherAmendment == null) { +// return distanceAverageEveryCycle; +// } +// +// if (surveyorWeatherAmendment.amendType == SurveyorPointScheduleRecord.AMMEND_TYPE_ORDINARY) { +// double ppm = getPpm(surveyorWeatherAmendment.getCalDampWarm(), surveyorWeatherAmendment.getCalAirPressure(), surveyorWeatherAmendment.getCalDryTemperature()); +// return ToolsTj.getAmendDistance(ppm, surveyorWeatherAmendment.additionConstant, surveyorWeatherAmendment.multiplyingConstant, surveyorWeatherAmendment.targetAdvance, distanceAverageEveryCycle); +// } else { +// return ToolsTj.getAmendDistance(surveyorWeatherAmendment.additionConstant, surveyorWeatherAmendment.multiplyingConstant, surveyorWeatherAmendment.targetAdvance, distanceAverageEveryCycle); +// } +// } + + /** + * 获取高精度修正距离 + */ +// private static double getHighPrecisionDistance(String stationId, int cycleIndex, String pointId, double distanceAverageEveryCycle) { +// ISurveyorPointWeatherAmendmentDataSource surveyorPointWeatherAmendmentDataSource = TjDbFactory.instance.getSurveyorPointWeatherAmendmentDataSource(); +// SurveyorPointWeatherAmendmentRecord surveyorWeatherAmendment = surveyorPointWeatherAmendmentDataSource.getSurveyorWeatherAmendment(stationId, cycleIndex, pointId, SurveyorPointScheduleRecord.AMMEND_TYPE_HIGH_PRECISION); +// if (surveyorWeatherAmendment == null) { +// return distanceAverageEveryCycle; +// } +// +// Map amemdMap = WeatherAmendmentMethod.getAmemdMap(surveyorWeatherAmendment); +// +// double stationDryTemperatureBeforeAmended = getTemperatureAmended(surveyorWeatherAmendment.stationDryTemperatureBefore, amemdMap, WeatherAmendmentConstants.KEY_STATION_DRY_TEMPERATURE_BEFORE); +// double stationDampWarmBeforeAmended = getTemperatureAmended(surveyorWeatherAmendment.stationDampWarmBefore, amemdMap, WeatherAmendmentConstants.KEY_STATION_DAMP_WARM_BEFORE); +// double stationAirPressureBeforeAmended = getAirpressureAmended(surveyorWeatherAmendment.stationAirPressureBefore, amemdMap, WeatherAmendmentConstants.KEY_STATION_AIR_PRESSURE_BEFORE, surveyorWeatherAmendment.stationDryTemperatureBefore); +// double targetDryTemperatureBeforeAmended = getTemperatureAmended(surveyorWeatherAmendment.targetDryTemperatureBefore, amemdMap, WeatherAmendmentConstants.KEY_TARGET_DRY_TEMPERATURE_BEFORE); +// double targetDampWarmBeforeAmended = getTemperatureAmended(surveyorWeatherAmendment.targetDampWarmBefore, amemdMap, WeatherAmendmentConstants.KEY_TARGET_DAMP_WARM_BEFORE); +// double targetAirPressureBeforeAmended = getAirpressureAmended(surveyorWeatherAmendment.targetAirPressureBefore, amemdMap, WeatherAmendmentConstants.KEY_TARGET_AIR_PRESSURE_BEFORE, surveyorWeatherAmendment.targetDryTemperatureBefore); +// double stationDryTemperatureAfterAmended = getTemperatureAmended(surveyorWeatherAmendment.stationDryTemperatureAfter, amemdMap, WeatherAmendmentConstants.KEY_STATION_DRY_TEMPERATURE_AFTER); +// double stationDampWarmAfterAmended = getTemperatureAmended(surveyorWeatherAmendment.stationDampWarmAfter, amemdMap, WeatherAmendmentConstants.KEY_STATION_DAMP_WARM_AFTER); +// double stationAirPressureAfterAmended = getAirpressureAmended(surveyorWeatherAmendment.stationAirPressureAfter, amemdMap, WeatherAmendmentConstants.KEY_STATION_AIR_PRESSURE_AFTER, surveyorWeatherAmendment.stationDryTemperatureAfter); +// double targetDryTemperatureAfterAmended = getTemperatureAmended(surveyorWeatherAmendment.targetDryTemperatureAfter, amemdMap, WeatherAmendmentConstants.KEY_TARGET_DRY_TEMPERATURE_AFTER); +// double targetDampWarmAfterAmended = getTemperatureAmended(surveyorWeatherAmendment.targetDampWarmAfter, amemdMap, WeatherAmendmentConstants.KEY_TARGET_DAMP_WARM_AFTER); +// double targetAirPressureAfterAmended = getAirpressureAmended(surveyorWeatherAmendment.targetAirPressureAfter, amemdMap, WeatherAmendmentConstants.KEY_TARGET_AIR_PRESSURE_AFTER, surveyorWeatherAmendment.targetDryTemperatureAfter); +// +// //求温度气压平均值 +// double dryTemperatureAverage = ((stationDryTemperatureBeforeAmended + stationDryTemperatureAfterAmended) / 2 + (targetDryTemperatureBeforeAmended + targetDryTemperatureAfterAmended) / 2) / 2; +// double dampWarmTemperatureAverage = ((stationDampWarmBeforeAmended + stationDampWarmAfterAmended) / 2 + (targetDampWarmBeforeAmended + targetDampWarmAfterAmended) / 2) / 2; +// double airPressureAverage = ((stationAirPressureBeforeAmended + stationAirPressureAfterAmended) / 2 + (targetAirPressureBeforeAmended + targetAirPressureAfterAmended) / 2) / 2; +// +// //求ppm +// double ppm = getPpm(dampWarmTemperatureAverage, airPressureAverage, dryTemperatureAverage); +// +// return ToolsTj.getAmendDistance(ppm, surveyorWeatherAmendment.additionConstant, surveyorWeatherAmendment.multiplyingConstant, surveyorWeatherAmendment.targetAdvance, distanceAverageEveryCycle); +// } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/ValueOf2cMethod.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/ValueOf2cMethod.java new file mode 100644 index 0000000..25ad8cd --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/ValueOf2cMethod.java @@ -0,0 +1,119 @@ +package com.bingce.controlnetwork.surveyor.method; + + +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.surveyor.method.DeviationValueOfRadianMethod; +import com.bingce.controlapphelper.surveyor.method.RadianMethod; +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; + +public class ValueOf2cMethod { + public static CacheResult valueOf2C(SdAngleValueType type, + String stationId, + int cycleIndex, + int pointIndex, + ISurveyorData surveyorData, + int surveyorCycleIndex, + ICachedData cachedData) { + CacheResult cachedValue = _valueOf2C(type, stationId, cycleIndex, pointIndex, surveyorData, surveyorCycleIndex, cachedData); + if (!cachedValue.validate) { + return cachedValue; + } + if (type == SdAngleValueType.horAngle || type == SdAngleValueType.verAngle) { + return new CacheResult(true, RadianMethod.radian2S(cachedValue.value)); + } + return new CacheResult(true, cachedValue.value * 1000); + } + + public static CacheResult valueOf2C(SdAngleValueType type, + String leftRecordId, + String rightRecordId, + int surveyorCount, + ICachedData cachedData) { + CacheResult cachedValue = _valueOf2C(type, leftRecordId, rightRecordId, surveyorCount, cachedData); + if (!cachedValue.validate) { + return cachedValue; + } + if (type == SdAngleValueType.horAngle || type == SdAngleValueType.verAngle) { + return new CacheResult(true, RadianMethod.radian2S(cachedValue.value)); + } + return new CacheResult(true, cachedValue.value * 1000); + } + + /** + * 2C值 + * + * @param type 类型(水平角、垂直角、斜距) + * @return 返回相应类型的2c + */ + private static CacheResult _valueOf2C(SdAngleValueType type, + String stationId, + int cycleIndex, + int pointIndex, + ISurveyorData surveyorData, + int surveyorCycleIndex, + ICachedData cachedData) { + CacheResult leftValue = AverageValueMethod.leftOrRightValue( + type, + stationId, + cycleIndex, + pointIndex, + surveyorData, + surveyorCycleIndex, + cachedData, LeftOrRight.left); + CacheResult rightValue = AverageValueMethod.leftOrRightValue( + type, + stationId, + cycleIndex, + pointIndex, + surveyorData, + surveyorCycleIndex, + cachedData, LeftOrRight.right); + if (leftValue.validate && rightValue.validate) { + switch (type) { + case horAngle: + return new CacheResult(true, DeviationValueOfRadianMethod.radianAngleHor2C(leftValue.value, rightValue.value)); + case verAngle: + return new CacheResult(true, DeviationValueOfRadianMethod.radianAngleVer2C(leftValue.value, rightValue.value)); + case distance: + return new CacheResult(true, DeviationValueOfRadianMethod.distance2C(leftValue.value, rightValue.value)); + } + } + + return new CacheResult(false, -1); + } + + + private static CacheResult _valueOf2C( + SdAngleValueType type, + String leftRecordId, + String rightRecordId, + int surveyorCount, + ICachedData cachedData) { + CacheResult leftValue = AverageValueMethod.leftOrRightValue( + type, + leftRecordId, + surveyorCount, + cachedData); + CacheResult rightValue = AverageValueMethod.leftOrRightValue( + type, + rightRecordId, + surveyorCount, + cachedData); + if (leftValue.validate && rightValue.validate) { + switch (type) { + case horAngle: + return new CacheResult(true, DeviationValueOfRadianMethod.radianAngleHor2C(leftValue.value, rightValue.value)); + case verAngle: + return new CacheResult(true, DeviationValueOfRadianMethod.radianAngleVer2C(leftValue.value, rightValue.value)); + case distance: + return new CacheResult(true, DeviationValueOfRadianMethod.distance2C(leftValue.value, rightValue.value)); + } + } + + return new CacheResult(false, -1); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/CacheResult.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/CacheResult.java new file mode 100644 index 0000000..1baab1b --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/CacheResult.java @@ -0,0 +1,11 @@ +package com.bingce.controlnetwork.surveyor.method.model; + +public class CacheResult { + public final boolean validate; + public final double value; + + public CacheResult(boolean validate, double value) { + this.validate = validate; + this.value = value; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/IStateDelegate.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/IStateDelegate.java new file mode 100644 index 0000000..57505eb --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/method/model/IStateDelegate.java @@ -0,0 +1,18 @@ +package com.bingce.controlnetwork.surveyor.method.model; + +import java.util.List; + +public interface IStateDelegate { + void onOptionTips(String msg, + String confirmButton, + String cancelButton, + Runnable confirmCallback, + Runnable cancelCallback, + Runnable ignoreCallback); + + void resetSurveyorStateAndKeepPosition(); + + void resurveyPoints(int cycleIndex, List pointIds); + + void deleteSingleCycleData(int cycleIndex); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/IAutoModeSwitcher.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/IAutoModeSwitcher.java new file mode 100644 index 0000000..2c0a809 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/IAutoModeSwitcher.java @@ -0,0 +1,27 @@ +package com.bingce.controlnetwork.surveyor.state; + + +import com.bingce.controlnetwork.surveyor.method.AutoSurveyorMethod; + +public interface IAutoModeSwitcher { + boolean isAutoModeOpen(); + + boolean isAutoModeClose(); + + boolean isAutoModeInit(); + + void openAutoMode(); + + void closeAutoMode(); + + void resetAutoMode(); + + void isReadyAutoSurvey(AutoSurveyorMethod.CallBackLearnResultCode callBackLearnResultCode); + + /** + * 自动测量过程中检测测量数据和设计数据是否匹配 + *

+ * 返回值为null就合法,否则出错 + */ + void isMeasuredValueMatchDesign(AutoSurveyorMethod.CallBackCheckDesign callBackCheckDesign); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyState.java new file mode 100644 index 0000000..c82637b --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyState.java @@ -0,0 +1,13 @@ +package com.bingce.controlnetwork.surveyor.state; + +public interface ISurveyState { + /** + * 是否正在测量,包括「单步测量」「自动测量」 + */ + boolean isSurveying(); + + /** + * 是否正在「自动测量」 + */ + boolean isAutoSurveying(); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyorDataScrollDelegate.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyorDataScrollDelegate.java new file mode 100644 index 0000000..a18d907 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/ISurveyorDataScrollDelegate.java @@ -0,0 +1,10 @@ +package com.bingce.controlnetwork.surveyor.state; + +/** + * 测量过程中,将跳转到当前item处 + *

+ * 这个委托就是做这项任务 + */ +public interface ISurveyorDataScrollDelegate { + void onScrollTo(int cycleIndex, int pointIndex); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateConstantsTj.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateConstantsTj.java new file mode 100644 index 0000000..679254e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateConstantsTj.java @@ -0,0 +1,54 @@ +package com.bingce.controlnetwork.surveyor.state; + +public class StateConstantsTj { + /** + * --------------------------measureWhat开始-------------------------------- + * 值勿改 + **/ + + /** + * 默认的 测角测距 + */ + public static final int VALUE_MEASURE_WHAT_DEFAULT = 0; + + /** + * 仅测距离 + */ + public static final int VALUE_MEASURE_WHAT_DISTANCE = 1; + + /** + * 仅测水平角 + */ + public static final int VALUE_MEASURE_WHAT_ANGLE_HOR = 2;//原3 + /** + * 仅测垂直角 + */ + public static final int VALUE_MEASURE_WHAT_ANGLE_VER = 3;//原4 + + + /** + * --------------------------measureWhat结束-------------------------------- + **/ + + + //measureWhat对应的传值key + public static final String KEY_IS_ALREADY_REMIND_USER_AIMING_AT_WIRE = "KEY_IS_ALREADY_REMIND_USER_AIMING_AT_WIRE"; + + + public static boolean needLeftRight(int measureWhat) { + return measureWhat == VALUE_MEASURE_WHAT_DEFAULT || measureWhat == VALUE_MEASURE_WHAT_ANGLE_HOR; + } + + public static boolean isMeasureDistance(int measureWhat) { + return measureWhat == VALUE_MEASURE_WHAT_DISTANCE; + } + + public static boolean isMeasureVerAngle(int measureWhat) { + return measureWhat == VALUE_MEASURE_WHAT_ANGLE_VER; + } + + public static boolean isZeroMeasureWhat(int measureWhat) { + return measureWhat == VALUE_MEASURE_WHAT_DEFAULT || measureWhat == VALUE_MEASURE_WHAT_ANGLE_HOR; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateManagerTj.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateManagerTj.java new file mode 100644 index 0000000..863ce72 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateManagerTj.java @@ -0,0 +1,243 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.content.Context; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IStationPointRecordCollect; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.state.base.AbstructStateManager; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.util.SupportAutoSurveyorUtil; + +public class StateManagerTj extends AbstructStateManager { + + private StateManagerTj(final int measureWhat, + final boolean supportAutoSurvey,//是否支持自动测量 + final @NonNull SurveyorStationRecord stationRecord, + final @NonNull PointRecord stationPointRecord, + final @NonNull ToleranceDetailRecord toleranceRecord, + final @NonNull Context context, + final @NonNull IStationPointRecordCollect pointRecordCollect, + final @NonNull ISurveyorData surveyorData, + final @NonNull ICycleRecorder cycleRecorder, + final @NonNull ICachedData cachedData, + final @NonNull ISurveyorDataScrollDelegate scrollDelegate, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner iuiRunner) { + super(measureWhat, supportAutoSurvey, stationRecord, stationPointRecord, + toleranceRecord, context, pointRecordCollect, surveyorData, cycleRecorder, + cachedData, scrollDelegate, fragmentManager, lifecycleOwner, iuiRunner); + } + + @Override + protected void initState() { + _DoSurveyorState doSurveyorState = new _DoSurveyorState(this, this); + stateMap.put(StateType.doSurveyor, doSurveyorState); + stateMap.put(StateType.doAutoSurveyor, new _DoAutoSurveyorState(this, this)); + stateMap.put(StateType.SurveyorFailure, new _SurveyorFailureState(this)); + stateMap.put(StateType.doMove2NextValidate, new _DoMove2NextValidateState(this)); + stateMap.put(StateType.doMoveBack, new _DoMoveBackState(this)); + stateMap.put(StateType.doRecordClean, new _DoRecordCleanState(this)); + stateMap.put(StateType.checkReadData, new _CheckReadDataState(this, this)); + stateMap.put(StateType.isHalfCycleZeroCheckReady, new _IsHalfCycleZeroCheckReadyState(this)); + stateMap.put(StateType.checkHalfCycleZero, new _CheckHalfCycleZeroState(this)); + stateMap.put(StateType.isReady2CCheck, new _Is2CCheckReadyState(this)); + stateMap.put(StateType.check2C, new _Check2CState(this)); + stateMap.put(StateType.isSingleCycleCompleted, new _IsSingleCycleCompletedState(this)); + stateMap.put(StateType.isAllCycleCompleted, new _IsAllCycleCompletedState(this, this)); + stateMap.put(StateType.checkSingleCycle, new _CheckSingleCycleState(this)); + stateMap.put(StateType.checkStation, new _CheckStationState(this)); + stateMap.put(StateType.stationCheckedSuccess, new _CheckStationSuccessState(this)); + + stateMap.put(StateType.doDeleteAllCycle, new _DoDeleteAllCycleState(this)); + stateMap.put(StateType.doDeleteCurrentCycle, new _DoDeleteCurrentCycleState(this)); + + stateMap.put(StateType.doCalScheduleSingleCycle, new _DoCalScheduleInSingleCycleState(this, this)); + stateMap.put(StateType.doCalScheduleAllCycle, new _DoCalScheduleInAllCycleState(this, this)); + stateMap.put(StateType.doCalAdjust, new _DoCalAdjustState(this)); + stateMap.put(StateType.idle, new _IdleState(this, this)); + stateMap.put(StateType.doWellMeasureRotationReady, new _DoWellMeasureRotationReadyState(this)); + } + + @Override + protected void refreshUiPage() { + getCachedData().notifyDateChange(); + } + + @Override + protected ISurveyorListener getISurveyorListener() { + return getDoSurveyorState(); + } + + @Override + protected ISurveyorRemindListener getISurveyorRemindListener() { + return getDoSurveyorState(); + } + + private _DoSurveyorState getDoSurveyorState() { + return (_DoSurveyorState) stateMap.get(StateType.doSurveyor); + } + + public void doSurveyor() { + boolean inValidate = isInValidate(); + boolean wellMeasureRotationReady = isWellMeasureRotationReady(); + + if (!(!inValidate || wellMeasureRotationReady)) { + //!inValidate是可以通过的状态 + return; + } + + if (Tools.isDeviceConnectedNot()) { + return; + } + + Bundle bundle = new Bundle(); + if (wellMeasureRotationReady) { + //当前是钢丝准备状态 + //传给测量状态isAlreadyRemindUserAimingAtWire + bundle.putBoolean(StateConstantsTj.KEY_IS_ALREADY_REMIND_USER_AIMING_AT_WIRE, true); + } + enter(StateType.doSurveyor, bundle); + } + + public void doAutoSurveyor() { + if (isInValidate()) { + return; + } + enter(StateType.doAutoSurveyor); + } + + public void deleteCurrentStationSurveyorData() { + if (isInValidate()) { + return; + } + enter(StateType.doDeleteAllCycle, _DoDeleteAllCycleState.args(stationId())); + } + + public void deleteCurrentStationSurveyorData(int cycleIndex) { + if (isInValidate()) { + return; + } + enter(StateType.doDeleteCurrentCycle, _DoDeleteCurrentCycleState.args(stationId(), cycleIndex)); + } + + public void stationCheck() { + if (isInValidate()) { + return; + } + enter(StateType.checkStation); + } + + public void stationAdjust() { + if (isInValidate()) { + return; + } + enter(StateType.doCalAdjust); + } + + public void switch2Cycle(int cycleIndex) { + if (isInValidate()) { + return; + } + _DoCalScheduleInSingleCycleState.enter(this, cycleIndex); + } + + public void calScheduleWhenEnterSurveyFragment(int cycleIndex) { + if (isInValidate()) { + return; + } + _DoCalScheduleInAllCycleState.enter(this, cycleIndex); + } + + public void moveBack() { + if (isInValidate()) { + return; + } + enter(StateType.doMoveBack); + } + + //检测当前状态是否支持从外界主动改变状态 + //如果是空闲或者是测站通过检测是有效的状态 + private boolean isInValidate() { + return currentStateType != StateType.idle && StateType.stationCheckedSuccess != currentStateType; + } + + private boolean isWellMeasureRotationReady() { + return StateType.doWellMeasureRotationReady == currentStateType; + } + + + @WorkerThread + public static StateManagerTj newInstance(int measureWhat,//仅测量水平角还是什么... + @NonNull SurveyorStationRecord stationRecord, + @NonNull Context context, + @NonNull FragmentManager fragmentManager, + @NonNull LifecycleOwner lifecycleOwner, + @NonNull ToleranceDetailRecord toleranceRecord, + @NonNull IStationPointRecordCollect pointRecordCollect, + @NonNull ISurveyorData surveyorData, + @NonNull ICycleRecorder cycleRecorder, + @NonNull ICachedData cachedData, + ISurveyorDataScrollDelegate scrollDelegate, + IUIRunner runner) { + //读取测点record + String stationPointId = null; + if (stationRecord.getItems() != null) { + for (SurveyorPoint stationItem : stationRecord.getItems()) { + if (SurveyorPoint.TYPE_STATION.equals(stationItem.getType())) { + stationPointId = stationItem.getPointId(); + break; + } + } + } + PointRecord stationPointRecord = null; + if (stationPointId != null) { + stationPointRecord = SurveyorDatabaseFactory + .instance + .getPointDataSource() + .findByIdSync(stationPointId); + } + if (stationPointRecord == null) { + return null; + } + boolean supportAuto = SupportAutoSurveyorUtil.isSupportAuto(); + return new StateManagerTj(measureWhat, supportAuto, + stationRecord, + stationPointRecord, + toleranceRecord, + context, + pointRecordCollect, + surveyorData, + cycleRecorder, + cachedData, + scrollDelegate, + fragmentManager, lifecycleOwner, runner); + } + + @Override + public boolean isSurveying() { + return currentStateType == StateType.doSurveyor || currentStateType == StateType.doAutoSurveyor; + } + + @Override + public boolean isAutoSurveying() { + return isAutoModeOpen(); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateType.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateType.java new file mode 100644 index 0000000..64a1c7d --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/StateType.java @@ -0,0 +1,36 @@ +package com.bingce.controlnetwork.surveyor.state; + +/* + * 标识状态类型 + * */ +public enum StateType { + idle,//空闲状态 + SurveyorFailure,//仪器导致的测量失败 + + doCalScheduleSingleCycle,//计算单个测回中的测量进度---不会发生跳转 + doCalScheduleAllCycle,//计算所有测回中的测量进度---可能发生跳转 + doCalAdjust,//平差计算 + doSurveyor,//测量 1 + doAutoSurveyor,//自动测量 + doRecordClean,//记录测量数据--目前没有发现错误 5 + doMove2NextValidate,//移动到下一点执行测量 + doMoveBack,//移动到上一测量结点 + doDeleteCurrentCycle,//删除本测回数据 + doDeleteAllCycle,//删除所有测回数据 + doWellMeasureRotationReady, + + isHalfCycleZeroCheckReady,//检测是否半测回完成 3 + isReady2CCheck,//是否满足进行2c检测条件 4 + isSingleCycleCompleted,//检测单个测回是否完成 6 + isAllCycleCompleted,//检测整个测回是否完成 + + checkReadData,//读数检测 2 + checkHalfCycleZero,//半测回归零差检测 + check2C,//2c检测 + checkSingleCycle,//单个测回内不同方向2c、方向i互差检测 + checkStation,//测回间数据检测-- 同方向方向值互差、2c互差、垂直角互差、i互差 + + stationCheckedSuccess,//测站通过检测 + + checkTolerance,//检测限差 +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Check2CState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Check2CState.java new file mode 100644 index 0000000..e1bc62e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Check2CState.java @@ -0,0 +1,186 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; +import android.text.TextUtils; + +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.ValueOf2cMethod; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.utils.Util; + +import net.tatans.tensorflowtts.tts.TtsManager; + +/* + * 检测2c + * */ +class _Check2CState extends __BaseState { + + public _Check2CState(StateManagerTj stateManager) { + super(StateType.check2C, stateManager); + } + + @Override + public void enter(Bundle args) { + String error = check2C(); + if (TextUtils.isEmpty(error)) { + navigation2(StateType.doRecordClean); + } else { + if (isAutoSurveyOpen()) { + TtsManager.getInstance().speak("二西超限,请检查"); + } + optionTips(error, + "重测测回", + "重测目标", + () -> optionTipsWithStandStill("是否确定删除该测回所有数据?", + () -> { + String stationId = stationId(); + int currentCycleIndex = getCycleRecorder().currentCycleIndex(); + if (currentCycleIndex == 0) { + deleteAllLearnBaseData(measureWhat(), stationId, this::clearSurveyData); + } else { + clearSurveyData(); + } + }), + this::enterIdleAndClearSurveyState, + this::enterIdleAndClearSurveyStateAndCloseAutoMode); + } + } + + private String check2C() { + int measureWhat = measureWhat(); + switch (measureWhat) { + case StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT: +// case StateConstants.VALUE_MEASURE_WHAT_ANGLE: + return checkAll(); + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR: + return checkAngleHor(); + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER: + return checkAngleVer(); + default: + return null; + } + } + + private void clearSurveyData() { + String stationId = stationId(); + int currentCycleIndex = getCycleRecorder().currentCycleIndex(); + //删除数据 + ICachedData cachedData = getCachedData(); + cachedData.deleteSurveyorRecord(stationId, currentCycleIndex); + //更新进度 + setStationScheduleForSingleCycle(currentCycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + //重新查找目标开启测量 + findTargetFromBeginInCurrentCycle(true); + } + + private String checkAll() { + StringBuilder stringBuilder = new StringBuilder(); + + int currentIndex = getSurveyorData().currentIndex(); + int cycleIndex = getCurrentCycleIndex(); + ICachedData cachedData = getCachedData(); + //检测水平角 + String errorHor = checkAngleHor(); + if (!TextUtils.isEmpty(errorHor)) { + stringBuilder.append(errorHor); + } + SurveyorPoint surveyorPoint = cachedData.getSurveyorPoint(cycleIndex, currentIndex); + boolean isWellSteel = cachedData.isWellSteelPoint(cycleIndex, currentIndex); + if (!isWellSteel && !surveyorPoint.isMeasureVerNot()) { + String errorVer = checkAngleVer(); + if (!TextUtils.isEmpty(errorVer)) { + stringBuilder.append(errorHor); + } + } + + if (!isWellSteel && !surveyorPoint.isMeasureDistanceNot()) { + String errorDistance = checkDistance(); + if (!TextUtils.isEmpty(errorDistance)) { + stringBuilder.append(errorDistance); + } + } + + return stringBuilder.toString(); + } + + private String checkAngleHor() { + StringBuilder stringBuilder = new StringBuilder(); + + ISurveyorData surveyorData = getSurveyorData(); + int currentIndex = getSurveyorData().currentIndex(); + String stationId = stationId(); + int cycleIndex = getCurrentCycleIndex(); + ICachedData cachedData = getCachedData(); + ToleranceDetailRecord toleranceRecord = getToleranceRecord(); + + CacheResult value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.horAngle, stationId, cycleIndex, currentIndex, + surveyorData, getCycleRecorder().currentCycleIndex(), cachedData); + + if (!value2C.validate || toleranceRecord.getHor2C() < Math.abs(value2C.value)) { + stringBuilder.append("水平角2c绝对值超限(限差:") + .append(toleranceRecord.getHor2C()) + .append("'')\n") + .append(" 测量值:") + .append(Util.formatDouble2String(Math.abs(value2C.value), 1)) + .append("''"); + } + + return stringBuilder.toString(); + } + + private String checkAngleVer() { + StringBuilder stringBuilder = new StringBuilder(); + + ISurveyorData surveyorData = getSurveyorData(); + int currentIndex = getSurveyorData().currentIndex(); + String stationId = stationId(); + int cycleIndex = getCurrentCycleIndex(); + ICachedData cachedData = getCachedData(); + ToleranceDetailRecord toleranceRecord = getToleranceRecord(); + + CacheResult value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, stationId, cycleIndex, currentIndex, + surveyorData, getCycleRecorder().currentCycleIndex(), cachedData); + if (!value2C.validate || toleranceRecord.getVerI() < Math.abs(value2C.value)) { + stringBuilder.append("\n竖直角i指标超限(限差:") + .append(toleranceRecord.getVerI()) + .append("'')\n") + .append(" 测量值:") + .append(Util.formatDouble2String(Math.abs(value2C.value), 1)) + .append("''"); + } + + return stringBuilder.toString(); + } + + private String checkDistance() { + StringBuilder stringBuilder = new StringBuilder(); + + ISurveyorData surveyorData = getSurveyorData(); + int currentIndex = getSurveyorData().currentIndex(); + String stationId = stationId(); + int cycleIndex = getCurrentCycleIndex(); + ICachedData cachedData = getCachedData(); + ToleranceDetailRecord toleranceRecord = getToleranceRecord(); + + CacheResult value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.distance, stationId, cycleIndex, currentIndex, + surveyorData, getCycleRecorder().currentCycleIndex(), cachedData); + if (!value2C.validate || toleranceRecord.getSlopeLensDistanceDifference() < Math.abs(value2C.value)) { + stringBuilder.append("\n正倒镜距离较差超限(限差:") + .append(toleranceRecord.getSlopeLensDistanceDifference()) + .append("mm)\n") + .append(" 测量值:") + .append(Util.formatDouble2String(Math.abs(value2C.value), 1)) + .append("mm"); + } + + return stringBuilder.toString(); + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckHalfCycleZeroState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckHalfCycleZeroState.java similarity index 74% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckHalfCycleZeroState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckHalfCycleZeroState.java index 156a56b..0671f64 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckHalfCycleZeroState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckHalfCycleZeroState.java @@ -1,20 +1,19 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.AverageValueMethod; -import com.bingce.controlapphelper.surveyor.method.DeviationValueOfRadianMethod; -import com.bingce.controlapphelper.surveyor.method.model.CacheResult; import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; -import com.bingce.controlapphelper.surveyor.state.StateType; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.AverageValueMethod; +import com.bingce.controlnetwork.surveyor.method.DeviationValueOfRadianMethod; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; import net.tatans.tensorflowtts.tts.TtsManager; -import com.bingce.controlnetwork.R; /* * 半测回归零检测 --- 只检测水平角 @@ -23,13 +22,19 @@ class _CheckHalfCycleZeroState extends __BaseState { private final static int RESULT_SUCCESS = 0; private final static int RESULT_FAILURE = 1; - public _CheckHalfCycleZeroState(StateManager stateManager) { + public _CheckHalfCycleZeroState(StateManagerTj stateManager) { super(StateType.checkHalfCycleZero, stateManager); } @Override public void enter(Bundle args) { if (isStationClosed()) { + + if (measureWhat() == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER) { + onCompleted(RESULT_SUCCESS); + return; + } + ISurveyorData surveyorDataSource = getSurveyorData(); int cycleIndex = getCycleRecorder().currentCycleIndex(); ICachedData stationSurveyorDataSource = getCachedData(); @@ -39,18 +44,18 @@ class _CheckHalfCycleZeroState extends __BaseState { CacheResult angleHorFirst = AverageValueMethod.leftOrRightValue(SdAngleValueType.horAngle, stationId(), + cycleIndex, 0, - leftOrRight, surveyorDataSource, - cycleIndex, - stationSurveyorDataSource); + getCycleRecorder().currentCycleIndex(), + stationSurveyorDataSource, leftOrRight); CacheResult angleHorEnd = AverageValueMethod.leftOrRightValue(SdAngleValueType.horAngle, stationId(), + cycleIndex, pointCount - 1, - leftOrRight, surveyorDataSource, - cycleIndex, - stationSurveyorDataSource); + getCycleRecorder().currentCycleIndex(), + stationSurveyorDataSource, leftOrRight); if (!angleHorFirst.validate || !angleHorEnd.validate) { onCompleted(RESULT_FAILURE); } else { @@ -73,7 +78,7 @@ class _CheckHalfCycleZeroState extends __BaseState { if (isAutoSurveyOpen()) { TtsManager.getInstance().speak(getContext().getString(R.string.tips_error_half_cycle_zero_stop_survey)); } - failureTipsWithAutoStandStill(getContext().getString(R.string.tips_error_half_cycle_zero_stop_survey)); + failureTipsWithAutoStandStill(getContext().getString(R.string.tips_error_half_cycle_zero_stop_survey), null); } else { throw new RuntimeException("半测回归零差 failure"); } diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckReadDataState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckReadDataState.java new file mode 100644 index 0000000..eefda7c --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckReadDataState.java @@ -0,0 +1,163 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.surveyor.method.RadianMethod; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.DeviationValueOfRadianMethod; + +import net.tatans.tensorflowtts.tts.TtsManager; + +/* + * 检测当前测量数据读数互差 + * */ +class _CheckReadDataState extends __BaseState { + private static final int RESULT_SUCCESS = 0; + private static final int RESULT_FAILURE_HOR = 1; + private static final int RESULT_FAILURE_VER = 2; + private static final int RESULT_FAILURE_DISTANCE = 3; + private final IAutoModeSwitcher autoModeSwitcher; + + public _CheckReadDataState(StateManagerTj stateManager, IAutoModeSwitcher autoModeSwitcher) { + super(StateType.checkReadData, stateManager); + this.autoModeSwitcher = autoModeSwitcher; + } + + @Override + public void enter(Bundle args) { + //先检测测量值和设计值是否匹配(仅在自动测量打开下检测) + autoModeSwitcher.isMeasuredValueMatchDesign(error -> { + if (error != null) { + failureTipsWithAutoStandStill(error, null); + return; + } + int surveyorCount = getToleranceRecord().getSurveyorCount(); + if (surveyorCount <= 1) {//单次测量,直接通过检测 + onCompleted(RESULT_SUCCESS); + } else {//多次测量,执行检测 + int measureWhat = measureWhat(); + int resultCode = RESULT_SUCCESS; + switch (measureWhat) { + case StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT: +// case StateConstants.VALUE_MEASURE_WHAT_ANGLE: + resultCode = checkAll(); + break; + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR: + resultCode = checkAngleHor(); + break; + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER: + resultCode = checkAngleVer(); + break; + } + onCompleted(resultCode); + } + }); + } + + private void onCompleted(int result) { + if (RESULT_SUCCESS == result) { + boolean checkLeftNot = checkLeftNot(false); + if (checkLeftNot) { + return; + } + navigation2(StateType.isHalfCycleZeroCheckReady); + } else { + String msg = ""; + switch (result) { + case RESULT_FAILURE_HOR: + msg = "水平角读数超限,请重新观测该目标."; + break; + case RESULT_FAILURE_VER: + msg = "垂直角读数超限,请重新观测该目标."; + break; + case RESULT_FAILURE_DISTANCE: + msg = "斜距读数超限,请重新观测该目标."; + break; + default: + navigation2(StateType.idle); + return; + } + if (isAutoSurveyOpen()) { + TtsManager.getInstance().speak(msg); + } + failureTipsWithAutoStandStill(msg, null); + } + } + + /** + * 斜距两次读数差 + * + * @param distance1 读数1 + * @param distance2 读数2 + * @return 读数差(单位毫米) + */ + public static double distanceReadDiff(double distance1, double distance2) { + return Math.abs(distance1 - distance2) * 1000; + } + + private int checkAll() { +// ISurveyorData surveyorDataSource = getSurveyorData(); + SurveyorPoint surveyorPoint = getCachedData().getSurveyorPoint(getCurrentCycleIndex(), getCurrentItemIndex()); +// double horDifference = getToleranceRecord().getHorReadDifference(); +// double verDifference = getToleranceRecord().getVerReadDifference(); +// double distanceDifference = getToleranceRecord().getSlopeReadDifference(); +// double horDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff(surveyorDataSource.getAngleHor1(), surveyorDataSource.getAngleHor2()); +// double verDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff(surveyorDataSource.getAngleVer1(), surveyorDataSource.getAngleVer2()); + + int resultCode = checkAngleHor(); + if (resultCode == RESULT_FAILURE_HOR) { + return resultCode; + } + + if (!isWellSteel() && !surveyorPoint.isMeasureVerNot()) { + resultCode = checkAngleVer(); + if (resultCode == RESULT_FAILURE_VER) { + return resultCode; + } + } + + if (!isWellSteel() && !surveyorPoint.isMeasureDistanceNot()) { + resultCode = checkDistance(); + if (resultCode == RESULT_FAILURE_DISTANCE) { + return resultCode; + } + } + + return RESULT_SUCCESS; + } + + private int checkAngleVer() { + ISurveyorData surveyorDataSource = getSurveyorData(); + double verDifference = getToleranceRecord().getVerReadDifference(); + double verDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff(surveyorDataSource.getAngleVer1(), surveyorDataSource.getAngleVer2()); + int resultCode = RESULT_SUCCESS; + if (verDifference < RadianMethod.radian2S(verDiffRadian)) { + resultCode = RESULT_FAILURE_VER; + } + return resultCode; + } + + private int checkAngleHor() { + ISurveyorData surveyorDataSource = getSurveyorData(); + double horDifference = getToleranceRecord().getHorReadDifference(); + double horDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff(surveyorDataSource.getAngleHor1(), surveyorDataSource.getAngleHor2()); + int resultCode = RESULT_SUCCESS; + if (horDifference < RadianMethod.radian2S(horDiffRadian)) { + resultCode = RESULT_FAILURE_HOR; + } + return resultCode; + } + + private int checkDistance() { + ISurveyorData surveyorDataSource = getSurveyorData(); + double distanceDifference = getToleranceRecord().getSlopeReadDifference(); + int resultCode = RESULT_SUCCESS; + if (distanceDifference < distanceReadDiff(surveyorDataSource.getDistance1(), surveyorDataSource.getDistance2())) { + resultCode = RESULT_FAILURE_DISTANCE; + } + return resultCode; + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckSingleCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckSingleCycleState.java similarity index 73% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckSingleCycleState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckSingleCycleState.java index d1f154a..55734c5 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckSingleCycleState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckSingleCycleState.java @@ -1,30 +1,28 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.datasource.database.surveyorrecord.SurveyorRecord; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.SingleCycleCheckMethod; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.IdUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.SingleCycleCheckMethod; import com.bingce.controlnetwork.surveyor.method.SingleCycleTipsMethod; +import com.bingce.controlnetwork.util.IdUtil; import net.tatans.tensorflowtts.tts.TtsManager; + /** * 测回内不同方向2c、方向i互差检测 */ class _CheckSingleCycleState extends __BaseState { - public _CheckSingleCycleState(StateManager stateManager) { + public _CheckSingleCycleState(StateManagerTj stateManager) { super(StateType.checkSingleCycle, stateManager); } @@ -39,10 +37,10 @@ class _CheckSingleCycleState extends __BaseState { for (int index = 0; index < pointCount; index++) { String pointId = cachedDataSource.pointId(currentCycleIndex, index); - String keyLeft = IdUtil.createSurveyorRecordId(stationId, currentCycleIndex, pointId, LeftOrRight.left); + String keyLeft = IdUtil.surveyorRecordKey(stationId, currentCycleIndex, pointId, LeftOrRight.left); SurveyorRecord left = cachedDataSource.getSurveyorRecord(keyLeft); _changeDirtyRecord2NormalBeforeCheck(left, cachedDataSource); - String keyRight = IdUtil.createSurveyorRecordId(stationId, currentCycleIndex, pointId, LeftOrRight.right); + String keyRight = IdUtil.surveyorRecordKey(stationId, currentCycleIndex, pointId, LeftOrRight.right); SurveyorRecord right = cachedDataSource.getSurveyorRecord(keyRight); _changeDirtyRecord2NormalBeforeCheck(right, cachedDataSource); } @@ -71,15 +69,16 @@ class _CheckSingleCycleState extends __BaseState { ToleranceDetailRecord toleranceRecord = getToleranceRecord(); ISurveyorData surveyorDataSource = getSurveyorData(); ICycleRecorder cycleRecorder = getCycleRecorder(); - ICachedData stationSurveyorDataSource = getCachedData(); + ICachedData cachedData = getCachedData(); //1.执行单测回内检测 String error = SingleCycleCheckMethod.check( + measureWhat(), toleranceRecord.getHorCycleDirect2CDifference(), toleranceRecord.getVerCycleDirectIDifference(), - stationId(), cycleRecorder.currentCycleIndex(), surveyorDataSource, stationSurveyorDataSource); + stationId(), cycleRecorder.currentCycleIndex(), surveyorDataSource, cycleRecorder, cachedData); if (error != null) { if (isAutoSurveyOpen()) { - TtsManager.getInstance().speak(Tools.getString(R.string.check_cycle_inner_failed)); + TtsManager.getInstance().speak("未通过测回内检测,请检查"); } //TODO 这里可能存在不对测回内错误处理的情况,后面应该兼容处理下 SingleCycleTipsMethod.showTips(error, stationId(), cycleRecorder.currentCycleIndex(), @@ -93,7 +92,7 @@ class _CheckSingleCycleState extends __BaseState { private void onSuccess() { //更新测量进度 - setSingleCycleSchedule(getCycleRecorder().currentCycleIndex(), + setStationScheduleForSingleCycle(getCycleRecorder().currentCycleIndex(), SurveyorScheduleConstants.STATUE_VALUE_CHECKED); //跳转 diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationState.java new file mode 100644 index 0000000..c272d38 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationState.java @@ -0,0 +1,411 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.point.IPointDataSource; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.ISurveyorStationDataSource; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.surveyor.method.RadianMethod; +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; +import com.bingce.controlapphelper.util.SurveyorCycleUtil; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.fragment.SelectReSurveyorPointFragment; +import com.bingce.controlnetwork.model.StationCheckErrorItem; +import com.bingce.controlnetwork.model.StationCheckErrorPoint; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.AverageValueMethod; +import com.bingce.controlnetwork.surveyor.method.DeviationValueOfRadianMethod; +import com.bingce.controlnetwork.surveyor.method.ValueOf2cMethod; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.controlnetwork.surveyor.state.base.CheckToleranceUtil; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.utils.Util; + +import java.util.ArrayList; +import java.util.List; + + +/** + * 执行「测站检测」 + *

+ * 前置条件: + * 所有测回都完成测量,并且通过「测回内检测」 + */ +class _CheckStationState extends __BaseState { + + public _CheckStationState(StateManagerTj stateManager) { + super(StateType.checkStation, stateManager); + } + + @Override + public void enter(Bundle args) { + //执行测站检测 + String error = _stationCheck(getStation(), getToleranceRecord(), getCachedData()); + if (error == null || error.isEmpty()) { + //进入finish状态 + navigation2(StateType.stationCheckedSuccess); + } else { + showErrorTips(error, stationId(), getCycleCount(), + getSurveyorData(), getCycleRecorder(), getCachedData(), + this, + fragmentManager(), + lifecycleOwner()); + } + } + + /** + * 提示错误信息,并让用户选择下一步操作 + */ + static void showErrorTips(String msg, String stationId, int cycleCount, + ISurveyorData surveyorDataSource, + ICycleRecorder cycleRecorder, + ICachedData stationSurveyorDataSource, + __BaseState state, + FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { + state.optionTips(msg, + "重测方向", + "重测测站", + () -> state.runOnBackground(() -> reSurveyorPoint(stationId, cycleCount, + cycleRecorder, stationSurveyorDataSource, + state, fragmentManager, lifecycleOwner)), + () -> reSurveyorStation(msg, stationId, cycleCount, + surveyorDataSource, cycleRecorder, stationSurveyorDataSource, + state, fragmentManager, lifecycleOwner), + () -> state.enterIdleAndClearSurveyStateAndResetAutoMode(true)); + } + + @WorkerThread + static void reSurveyorPoint(String stationId, int cycleCount, + ICycleRecorder cycleRecorder, + ICachedData cachedData, + __BaseState state, + FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { + //弹框提示选择重测数据 + ISurveyorStationDataSource dataSource = SurveyorDatabaseFactory.instance.getSurveyorStation(); + SurveyorStationRecord instance = dataSource.getRecordSync(stationId); + if (instance == null) { + state.enterIdleAndClearSurveyStateAndResetAutoMode(true); + return; + } + IPointDataSource pointDataSource = SurveyorDatabaseFactory.instance.getPointDataSource(); + List stationItems = instance.getItems(); + ArrayList ids = new ArrayList<>(); + ArrayList names = new ArrayList<>(); + for (SurveyorPoint item : stationItems) { + if (item.isAbandon()) { + continue; + } + + if (!SurveyorPoint.TYPE_POINT.equals(item.getType())) { + continue; + } + PointRecord pointRecord = pointDataSource.findByIdSync(item.getPointId()); + if (pointRecord == null) { + continue; + } + ids.add(pointRecord.id); + names.add(pointRecord.name); + } + state.runOnUI(() -> SelectReSurveyorPointFragment.pick( + fragmentManager, + lifecycleOwner, + cycleCount, + instance.leftAndRightSurveyor, + ids, + names, + (cycleIndex, pointIds) -> { + if (pointIds == null || pointIds.isEmpty()) { + state.enterIdleAndClearSurveyStateAndResetAutoMode(true); + } else { + //记录补测数据类型,切换测回 + cachedData.markReSurveyor(stationId, cycleIndex, pointIds); + cycleRecorder.changeCycleIndex(cycleIndex); + + //更新测量状态 + state.setStationCycle(cycleIndex); + state.setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + state.setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + + //查找新测量目标 + state.findTargetFromBeginInCurrentCycle(true); + } + } + )); + } + + static void reSurveyorStation(String msg, String stationId, int cycleCount, + ISurveyorData surveyorData, + ICycleRecorder cycleRecorder, + ICachedData cachedData, + __BaseState state, + FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { + state.optionTips("是否确定删除该测站所有数据?", null, null, + () -> {//1.选择删除测站所有数据,则执行相应逻辑 + //删除数据 + cachedData.deleteSurveyorRecord(stationId); + + //更新测量进度 + state.setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + for (int index = 0; index < cycleCount; index++) { + state.setStationScheduleForSingleCycle(index, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + } + //新增 + state.setStationCycle(0); + + //重新测量 + state.findTargetFromBeginInCurrentCycle(true); + }, + () -> {//2.如果用户不选择删除,则循环提示,让他重新在重测和删除做选择 + //循环显示 + showErrorTips(msg, stationId, cycleCount, + surveyorData, cycleRecorder, cachedData, state, + fragmentManager, lifecycleOwner); + }, + () -> state.enterIdleAndClearSurveyStateAndResetAutoMode(true));//3.如果用户忽略,则停留在当前位置 + } + + + //检测合法性 + + /** + * 检测所有测回数据 + *

+ * 在「无自动闭合」情况下,为了兼容「左右角」测量结果,根据pointId将所有测量数据存入map中 + * 根据「左角」测量来检测「测回间同方向值互差」,所有测回的归零值使用「左角」第一个point来做0点 + *

+ * 如果是「自动闭合」情况,则忽略「左右角」测量,直接按照itemIndex依次计算,第个测回的归零值, + * 使用每次循环的itemIndex=0做0点 + * + * @param toleranceRecord 限差 + * @param cachedDataSource 缓存的测量数据 + * @return 错误信息,如果为null或空,说明没有错误 + */ + public String _stationCheck( + final SurveyorStationRecord stationRecord, + final ToleranceDetailRecord toleranceRecord, + final ICachedData cachedDataSource) { + int measureWhat = measureWhat(); + String stationId = stationRecord.getId(); + final int cycleCount = getCycleCount(); + final int surveyorCount = toleranceRecord.getSurveyorCount(); + + //*****测回间同方向值互差(水平角) + double horCyclesDirectValueDifference = toleranceRecord.getHorCyclesDirectValueDifference()/*horCyclesDirectValueDifference*/; + List horValueError = new ArrayList<>(); + //*****测回间垂直角互差(垂直角) + double verCyclesAngleDifference = toleranceRecord.getVerCyclesAngleDifference()/*verCyclesAngleDifference*/; + List verValueError = new ArrayList<>(); + + //执行计算 + for (int cycleI = 0; cycleI < cycleCount; cycleI++) { + List valuesI = + DeviationValueOfRadianMethod.zeroValueOfSingleCycleInLeftOrientation(measureWhat(), stationId, cycleI, surveyorCount, cachedDataSource); + + if (valuesI.isEmpty()) { + return "第" + (cycleI + 1) + "测回,数据不完整!"; + } + + for (int cycleJ = cycleI + 1; cycleJ < cycleCount; cycleJ++) { + List valuesJ = + DeviationValueOfRadianMethod.zeroValueOfSingleCycleInLeftOrientation(measureWhat(), stationId, cycleJ, surveyorCount, cachedDataSource); + if (valuesI.size() != valuesJ.size()) { + return "第" + (cycleJ + 1) + "测回,数据不完整!"; +// return "请完成所有重测后再检测测站数据!"; + } + int size = valuesI.size(); + for (int index = 0; index < size; index++) { + + if (CheckToleranceUtil.checkAngleHor(measureWhat)) { + double diff = Math.abs( + DeviationValueOfRadianMethod + .similarRadianDiff( + valuesI.get(index).horRadian, + valuesJ.get(index).horRadian)); + if (horCyclesDirectValueDifference < RadianMethod.radian2S(diff)) { + horValueError.add(new StationCheckErrorItem(valuesI.get(index).pointName, + cycleI, cycleJ, RadianMethod.radian2S(diff))); + } + } + +// if (valuesI.get(index).verRadian == FaultTolerantData.WELL_ERROR_VER_ANGLE +// && valuesJ.get(index).verRadian == FaultTolerantData.WELL_ERROR_VER_ANGLE) { +// //当是井定向的时候垂直角不验证 +// continue; +// } + + if (CheckToleranceUtil.checkAngleVer(measureWhat)) { + double diff = Math.abs(DeviationValueOfRadianMethod + .similarRadianDiff(valuesI.get(index).verRadian, valuesJ.get(index).verRadian)); + if (verCyclesAngleDifference < RadianMethod.radian2S(diff)) { + verValueError.add(new StationCheckErrorItem(valuesI.get(index).pointName, + cycleI, cycleJ, RadianMethod.radian2S(diff))); + } + } + + } + } + } + //*****测回间垂直角I互差(垂直角) + double verCyclesIDifference = toleranceRecord.getVerCyclesIDifference()/*verCyclesIDifference*/; + List verIError = new ArrayList<>(); + //*****测回间斜距互差(距离) + double distCyclesDifference = toleranceRecord.getSlopeCycleDistanceDifference()/*slopeCycleDistanceDifference*/; + List distError = new ArrayList<>(); + + List pointArrayList = new ArrayList<>(); + //遍历第一测回,收集所有待测点id + for (int index = 0; index < cachedDataSource.pointCount(); index++) { + if (cachedDataSource.isAbandonPoint(0, index)) { + continue; + } + if (cachedDataSource.isWellSteelPoint(0, index)) { + continue; + } + if (cachedDataSource.isAloneMeasureDistancePoint(0, index)) { + continue; + } + pointArrayList.add(new StationCheckErrorPoint(cachedDataSource.pointId(0, index), cachedDataSource.pointName(0, index))); + } + //检测所有待测点i互差 + for (StationCheckErrorPoint point : pointArrayList) { + for (int cycleI = 0; cycleI < cycleCount; cycleI++) { + String leftRecordId_I = IdUtil.surveyorRecordKey(stationId, cycleI, point.pointId, LeftOrRight.left); + String rightRecordId_I = IdUtil.surveyorRecordKey(stationId, cycleI, point.pointId, LeftOrRight.right); + CacheResult value2C_I = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, leftRecordId_I, rightRecordId_I, + toleranceRecord.getSurveyorCount(), cachedDataSource); + CacheResult distanceLeftAndRightAverageValue_I = AverageValueMethod.leftAndRightValue(SdAngleValueType.distance, + leftRecordId_I, + rightRecordId_I, surveyorCount, cachedDataSource); + for (int cycleJ = cycleI + 1; cycleJ < cycleCount; cycleJ++) { + String leftRecordId_J = IdUtil.surveyorRecordKey(stationId, cycleJ, point.pointId, LeftOrRight.left); + String rightRecordId_J = IdUtil.surveyorRecordKey(stationId, cycleJ, point.pointId, LeftOrRight.right); + CacheResult value2C_J = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, leftRecordId_J, rightRecordId_J, + toleranceRecord.getSurveyorCount(), cachedDataSource); + CacheResult distanceLeftAndRightAverageValue_J = AverageValueMethod.leftAndRightValue(SdAngleValueType.distance, + leftRecordId_J, + rightRecordId_J, surveyorCount, cachedDataSource); + double verI = Math.abs(value2C_I.value - value2C_J.value); + if (verCyclesIDifference < verI) { + if (CheckToleranceUtil.checkAngleVer(measureWhat)) { + verIError.add(new StationCheckErrorItem(point.pointName, cycleI, cycleJ, verI)); + } + } + double distance = Math.abs(distanceLeftAndRightAverageValue_I.value - distanceLeftAndRightAverageValue_J.value); + if (distCyclesDifference < distance * 1000) { + // TODO: 2022/7/20 修改 原先不是distError + if (CheckToleranceUtil.checkDistance(measureWhat)) { + distError.add(new StationCheckErrorItem(point.pointName, cycleI, cycleJ, distance * 1000)); + } + } + } + } + } + + return _errorString(horCyclesDirectValueDifference, verCyclesAngleDifference, verCyclesIDifference, distCyclesDifference, + horValueError, verValueError, verIError, distError); + } + + /** + * 根据超限信息生成错误描述 + * + * @param horValueError 水平角同方向值互差 + * @param verValueError 垂直角同方向值互差 + */ + private static String _errorString(double horLimit, double verLimit, double verILimit, double distLimit, + List horValueError, List verValueError, + List verIError, List distError) { + if (horValueError.isEmpty() && verValueError.isEmpty()) { + return null; + } + StringBuilder stringBuilder = new StringBuilder(); + if (!horValueError.isEmpty()) { + stringBuilder.append("测回间同方向值互差超限(限差:") + .append(Util.formatDouble2String(horLimit, 1)) + .append("'')"); + for (StationCheckErrorItem item : horValueError) { + stringBuilder + .append("\n ") + .append(item.pointName) + .append(":\n") + .append(" |") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) + .append("-") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) + .append("| = ") + .append(Util.formatDouble2String(item.difference, 1)) + .append("'')"); + } + } + + if (!verValueError.isEmpty()) { + stringBuilder.append("\n测回间垂直角互差超限(限差:") + .append(Util.formatDouble2String(verLimit, 1)) + .append("'')"); + for (StationCheckErrorItem item : verValueError) { + stringBuilder + .append("\n ") + .append(item.pointName) + .append(":\n") + .append(" |") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) + .append("-") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) + .append("| = ") + .append(Util.formatDouble2String(item.difference, 1)) + .append("'')"); + } + } + + if (!verIError.isEmpty()) { + stringBuilder.append("\n垂直角i指标同方向各测回较差超限(限差:") + .append(Util.formatDouble2String(verILimit, 1)) + .append("'')"); + for (StationCheckErrorItem item : verIError) { + stringBuilder + .append("\n ") + .append(item.pointName) + .append(":\n") + .append(" |") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) + .append("-") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) + .append("| = ") + .append(Util.formatDouble2String(item.difference, 1)) + .append("'')"); + } + } + + if (!distError.isEmpty()) { + stringBuilder.append("\n测回间距离较差超限(限差:") + .append(Util.formatDouble2String(distLimit, 1)) + .append("'')"); + for (StationCheckErrorItem item : distError) { + stringBuilder + .append("\n ") + .append(item.pointName) + .append(":\n") + .append(" |") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) + .append("-") + .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) + .append("| = ") + .append(Util.formatDouble2String(item.difference, 1)) + .append("'')"); + } + } + + return stringBuilder.toString(); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationSuccessState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationSuccessState.java similarity index 67% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationSuccessState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationSuccessState.java index ffe951f..2706f21 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationSuccessState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_CheckStationSuccessState.java @@ -1,18 +1,17 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; import net.tatans.tensorflowtts.tts.TtsManager; -import com.bingce.controlnetwork.R; class _CheckStationSuccessState extends __BaseState { - public _CheckStationSuccessState(StateManager stateManager) { + public _CheckStationSuccessState(StateManagerTj stateManager) { super(StateType.stationCheckedSuccess, stateManager); } @@ -21,7 +20,7 @@ class _CheckStationSuccessState extends __BaseState { ISurveyorData surveyorData = getSurveyorData(); surveyorData.clearSurveyStateAndPosition(); //设置测量进度(数据库存储) - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_CHECKED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_CHECKED); //通知刷新 tips(getContext().getString(R.string.tips_all_cycle_has_finish_and_checked), null); if (isAutoSurveyOpen()) { diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoAutoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoAutoSurveyorState.java new file mode 100644 index 0000000..1667684 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoAutoSurveyorState.java @@ -0,0 +1,30 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import com.bingce.totalstation.ControlSurveyResult; + +import net.tatans.tensorflowtts.tts.TtsManager; + +/** + * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 + */ +class _DoAutoSurveyorState extends __BaseState { + private final IAutoModeSwitcher autoModeSwitcher; + + public _DoAutoSurveyorState(StateManagerTj stateManager, IAutoModeSwitcher autoModeSwitcher) { + super(StateType.doAutoSurveyor, stateManager); + this.autoModeSwitcher = autoModeSwitcher; + } + + @Override + public void enter(Bundle args) { + autoModeSwitcher.isReadyAutoSurvey(code -> { + if (code == ControlSurveyResult.CODE_SUCCESS) { + autoModeSwitcher.openAutoMode(); + navigation2(StateType.doMove2NextValidate); + TtsManager.getInstance().speak("开始自动测量"); + } + }); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalAdjustState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalAdjustState.java new file mode 100644 index 0000000..67c1c91 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalAdjustState.java @@ -0,0 +1,47 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; +import android.text.TextUtils; + +import androidx.annotation.NonNull; + +import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; +import com.bingce.controlnetwork.surveyor.method.SurveyorAdjustMethodTj; + + +/** + * 平差计算 + */ +public class _DoCalAdjustState extends __BaseState { + + public _DoCalAdjustState(StateManagerTj stateManager) { + super(StateType.doCalAdjust, stateManager); + } + + @Override + public void enter(@NonNull Bundle args) { + runOnBackground(() -> { + SurveyorAdjustMethodTj.AdjustResult adjustResult = SurveyorAdjustMethodTj.calStationAdjust(measureWhat(), getStation(), getCachedData()); + if (!TextUtils.isEmpty(adjustResult.errorString)) { + runOnUI(() -> _CheckStationState.showErrorTips(adjustResult.errorString, stationId(), getCycleCount(), + getSurveyorData(), getCycleRecorder(), getCachedData(), + _DoCalAdjustState.this, + fragmentManager(), + lifecycleOwner())); + return; + } + + //清除测量状态,进入idle,停止自动测量 + enterIdleAndClearSurveyStateAndResetAutoMode(true); + //展示结果数据 + //检测归零值是否为负,如果是需要+2PI + for (SurveyorAdjustMethodTj.Item item : adjustResult.result) { + if (item.getHorAngle() < 0) { + item.setHorAngle(Math.PI * 2 + item.getHorAngle()); + } + } + StationDataAdjustDialogFragment.showDialog(measureWhat(), adjustResult.result, getStation().isShowSlopDistance(), fragmentManager()); + }); + + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalScheduleInAllCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalScheduleInAllCycleState.java similarity index 77% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalScheduleInAllCycleState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalScheduleInAllCycleState.java index a28e35e..9482f2b 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalScheduleInAllCycleState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalScheduleInAllCycleState.java @@ -1,22 +1,21 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; import com.bingce.controlapphelper.datasource.database.schedule.ISurveyorScheduleDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.method.FindTargetMethod; -import com.bingce.controlapphelper.surveyor.method.SingleCycleCheckMethod; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.method.FindTargetMethod; +import com.bingce.controlnetwork.surveyor.method.SingleCycleCheckMethod; import com.bingce.controlnetwork.surveyor.method.SingleCycleTipsMethod; import com.bingce.utils.ThreadPoolUtil; + /** * 在所有测回范围计算测量进度。 *

@@ -32,7 +31,7 @@ import com.bingce.utils.ThreadPoolUtil; */ class _DoCalScheduleInAllCycleState extends _DoCalScheduleInSingleCycleState { - public _DoCalScheduleInAllCycleState(StateManager stateManager, IAutoModeSwitcher autoModeSwitcher) { + public _DoCalScheduleInAllCycleState(StateManagerTj stateManager, IAutoModeSwitcher autoModeSwitcher) { super(StateType.doCalScheduleAllCycle, stateManager, autoModeSwitcher); } @@ -40,18 +39,18 @@ class _DoCalScheduleInAllCycleState extends _DoCalScheduleInSingleCycleState { protected boolean isNeedCancelEnterIdle(int currentCycle) { ICachedData cachedData = getCachedData(); int pointCount = cachedData.pointCount(); - ToleranceDetailRecord toleranceDetailRecord = getToleranceRecord(); + ToleranceDetailRecord toleranceDetailRecordTj = getToleranceRecord(); //5.当前测回完成且通过检测,则对其他测回执行检测 FindTargetMethod.Target resurveyTarget = null; int emptyCycleIndex = -1; - for (int cycleIndex = 0; cycleIndex < toleranceDetailRecord.getCycleCount(); cycleIndex++) { + for (int cycleIndex = 0; cycleIndex < getCycleCount(); cycleIndex++) { if (cycleIndex == getCycleRecorder().currentCycleIndex()) { continue; } if (_IsSingleCycleCompletedState.isSingleCycleCompleted(stationId(), cycleIndex, getCachedData())) { //更新该测回进度 - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); continue; } //从0号位置盘左开始向后查询,找到需要补测位置 @@ -78,18 +77,20 @@ class _DoCalScheduleInAllCycleState extends _DoCalScheduleInSingleCycleState { return true; } //8.所有测回都完成测量(当前测回完成检测),执行检测 - double horCycle2CDiff = toleranceDetailRecord.getHorCycleDirect2CDifference(); - double verCycle2CDiff = toleranceDetailRecord.getVerCycleDirectIDifference(); - for (int cycleIndex = 0; cycleIndex < toleranceDetailRecord.getCycleCount(); cycleIndex++) { + double horCycle2CDiff = toleranceDetailRecordTj.getHorCycleDirect2CDifference(); + double verCycle2CDiff = toleranceDetailRecordTj.getVerCycleDirectIDifference(); + for (int cycleIndex = 0; cycleIndex < getCycleCount(); cycleIndex++) { if (cycleIndex == getCycleRecorder().currentCycleIndex()) { continue; } String result = SingleCycleCheckMethod.check( + measureWhat(), horCycle2CDiff, verCycle2CDiff, stationId(), cycleIndex, getSurveyorData(), + getCycleRecorder(), getCachedData()); if (result != null && !result.isEmpty()) { SingleCycleTipsMethod.showTips(result, @@ -101,14 +102,14 @@ class _DoCalScheduleInAllCycleState extends _DoCalScheduleInSingleCycleState { return true; } //更新该测回进度 - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_CHECKED); + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_CHECKED); } //9.所有测回都通过检测,可以执行「测站检测」 //设置测量进度,但是需要注意,如果station已经通过检测,则不需要设置为completed ThreadPoolUtil.execute(() -> { ISurveyorScheduleDataSource scheduleDataSource = SurveyorDatabaseFactory.instance.getScheduleDataSource(); - String key = SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null); + String key = SurveyorScheduleConstants.stationAllCycleScheduleKey(stationId(), stateManager.getMeasureWhat()); SurveyorScheduleRecord scheduleRecord = scheduleDataSource.findScheduleSync(key); if (scheduleRecord != null) { String statue = scheduleRecord.getStatue(); @@ -126,7 +127,7 @@ class _DoCalScheduleInAllCycleState extends _DoCalScheduleInSingleCycleState { return true; } - static void enter(StateManager stateManager, int cycleIndex) { + static void enter(StateManagerTj stateManager, int cycleIndex) { Bundle args = new Bundle(); args.putInt(KEY_CYCLE_INDEX, cycleIndex); stateManager.enter(StateType.doCalScheduleAllCycle, args); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalScheduleInSingleCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalScheduleInSingleCycleState.java similarity index 73% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalScheduleInSingleCycleState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalScheduleInSingleCycleState.java index 527ced4..8574d48 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalScheduleInSingleCycleState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoCalScheduleInSingleCycleState.java @@ -1,13 +1,11 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.method.SingleCycleCheckMethod; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.method.SingleCycleCheckMethod; import com.bingce.controlnetwork.surveyor.method.SingleCycleTipsMethod; /** @@ -20,12 +18,12 @@ import com.bingce.controlnetwork.surveyor.method.SingleCycleTipsMethod; class _DoCalScheduleInSingleCycleState extends __BaseState { private final IAutoModeSwitcher autoModeSwitcher; - public _DoCalScheduleInSingleCycleState(StateManager stateManager, IAutoModeSwitcher autoModeSwitcher) { + public _DoCalScheduleInSingleCycleState(StateManagerTj stateManager, IAutoModeSwitcher autoModeSwitcher) { super(StateType.doCalScheduleSingleCycle, stateManager); this.autoModeSwitcher = autoModeSwitcher; } - protected _DoCalScheduleInSingleCycleState(StateType stateType, final StateManager stateManager, IAutoModeSwitcher autoModeSwitcher) { + protected _DoCalScheduleInSingleCycleState(StateType stateType, final StateManagerTj stateManager, IAutoModeSwitcher autoModeSwitcher) { super(stateType, stateManager); this.autoModeSwitcher = autoModeSwitcher; } @@ -49,8 +47,9 @@ class _DoCalScheduleInSingleCycleState extends __BaseState { getSurveyorData().clearSurveyStateAndPosition(); ICycleRecorder cycleRecorder = getCycleRecorder(); - cycleRecorder.changeCycleIndex(args.getInt(KEY_CYCLE_INDEX, 0)); - setCurrentCycle(cycleRecorder.currentCycleIndex()); + int cycleIndex = args.getInt(KEY_CYCLE_INDEX, 0); + cycleRecorder.changeCycleIndex(cycleIndex); + setStationCycle(cycleIndex); //1.检测当前cycle是否完成测量 boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( @@ -64,15 +63,17 @@ class _DoCalScheduleInSingleCycleState extends __BaseState { return; } //3.如果当前测回结束测量,判断是否通过检测 - ToleranceDetailRecord toleranceDetailRecord = getToleranceRecord(); - double horCycle2CDiff = toleranceDetailRecord.getHorCycleDirect2CDifference(); - double verCycle2CDiff = toleranceDetailRecord.getVerCycleDirectIDifference(); + ToleranceDetailRecord toleranceDetailRecordTj = getToleranceRecord(); + double horCycle2CDiff = toleranceDetailRecordTj.getHorCycleDirect2CDifference(); + double verCycle2CDiff = toleranceDetailRecordTj.getVerCycleDirectIDifference(); String error = SingleCycleCheckMethod.check( + measureWhat(), horCycle2CDiff, verCycle2CDiff, stationId(), getCycleRecorder().currentCycleIndex(), getSurveyorData(), + getCycleRecorder(), getCachedData()); if (error != null && !error.isEmpty()) { SingleCycleTipsMethod.showTips(error, @@ -84,7 +85,7 @@ class _DoCalScheduleInSingleCycleState extends __BaseState { return; } //4.更新测站状态 - setSingleCycleSchedule(getCycleRecorder().currentCycleIndex(), + setStationScheduleForSingleCycle(getCycleRecorder().currentCycleIndex(), SurveyorScheduleConstants.STATUE_VALUE_CHECKED); //5.检测其他测回状态 @@ -102,7 +103,7 @@ class _DoCalScheduleInSingleCycleState extends __BaseState { protected static final String KEY_CYCLE_INDEX = "___cycle__index__"; - static void enter(StateManager stateManager, int cycleIndex) { + static void enter(StateManagerTj stateManager, int cycleIndex) { Bundle args = new Bundle(); args.putInt(KEY_CYCLE_INDEX, cycleIndex); stateManager.enter(StateType.doCalScheduleSingleCycle, args); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteAllCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteAllCycleState.java new file mode 100644 index 0000000..9a53787 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteAllCycleState.java @@ -0,0 +1,51 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; + + +/* + * 删除本测站所有测回数据 + * */ +class _DoDeleteAllCycleState extends __BaseState { + + public _DoDeleteAllCycleState(StateManagerTj stateManager) { + super(StateType.doDeleteAllCycle, stateManager); + } + + @Override + public void enter(Bundle args) { + String stationId = args.getString(KEY_STATION_ID); + + optionTipsWithStandStill(getContext().getString(R.string.tips_delete_station_all_surveyor_records), + () -> { + //删除数据 + ICachedData cachedData = getCachedData(); + cachedData.deleteSurveyorRecord(stationId); + + deleteAllLearnBaseData(measureWhat(), stationId, () -> { + //重置进度 + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + for (int cycleIndex = 0; cycleIndex < getCycleCount(); cycleIndex++) { + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + } + //从第一测回开始 + setStationCycle(0); + //重新测量,并刷新 + findTargetFromBeginInCurrentCycle(true); + }); + + }); + } + + private static final String KEY_STATION_ID = "__station_id"; + + static Bundle args(String stationId) { + Bundle args = new Bundle(); + args.putString(KEY_STATION_ID, stationId); + return args; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteCurrentCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteCurrentCycleState.java new file mode 100644 index 0000000..6a8dffc --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoDeleteCurrentCycleState.java @@ -0,0 +1,53 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; + + +class _DoDeleteCurrentCycleState extends __BaseState { + public _DoDeleteCurrentCycleState(StateManagerTj stateManager) { + super(StateType.doDeleteCurrentCycle, stateManager); + } + + @Override + public void enter(Bundle args) { + String stationId = args.getString(KEY_STATION_ID); + int cycleIndex = args.getInt(KEY_PERIOD_INDEX); + + optionTipsWithStandStill(getContext().getString(R.string.tips_delete_current_cycle_surveyor_record), + () -> { + if (cycleIndex == 0) { + deleteAllLearnBaseData(measureWhat(), stationId, () -> { + clearSurveyData(stationId, cycleIndex); + }); + } else { + clearSurveyData(stationId, cycleIndex); + } + }); + } + + private void clearSurveyData(String stationId, int cycleIndex) { + ICachedData stationSurveyorDataSource = getCachedData(); + stationSurveyorDataSource.deleteSurveyorRecord(stationId, cycleIndex); + + //重置进度 + setStationCycle(cycleIndex); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + //重新测量,并刷新 + findTargetFromBeginInCurrentCycle(true); + } + + private static final String KEY_STATION_ID = "__station_id"; + private static final String KEY_PERIOD_INDEX = "__period_index__"; + + static Bundle args(String stationId, int periodIndex) { + Bundle args = new Bundle(); + args.putString(KEY_STATION_ID, stationId); + args.putInt(KEY_PERIOD_INDEX, periodIndex); + return args; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoMove2NextValidateState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoMove2NextValidateState.java similarity index 81% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoMove2NextValidateState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoMove2NextValidateState.java index 7afaeb3..347b082 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoMove2NextValidateState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoMove2NextValidateState.java @@ -1,15 +1,12 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.FindTargetMethod; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.FindTargetMethod; import net.tatans.tensorflowtts.tts.TtsManager; @@ -22,7 +19,7 @@ import net.tatans.tensorflowtts.tts.TtsManager; */ class _DoMove2NextValidateState extends __BaseState { - public _DoMove2NextValidateState(StateManager stateManager) { + public _DoMove2NextValidateState(StateManagerTj stateManager) { super(StateType.doMove2NextValidate, stateManager); } @@ -63,7 +60,7 @@ class _DoMove2NextValidateState extends __BaseState { if (isAutoSurveyOpen()) { if (emptyTarget.itemIndex == getCachedData().pointCount() - 1 && emptyTarget.leftOrRight == LeftOrRight.right) { - TtsManager.getInstance().speak(Tools.getString(R.string.start_face_right)); + TtsManager.getInstance().speak("开始盘右测量"); } } //直接跳转到目标点,开启新测量 @@ -90,6 +87,6 @@ class _DoMove2NextValidateState extends __BaseState { enterIdleAndClearSurveyStateAndResetAutoMode(false); //滚动 - scroll2(targetIndex); + scroll2(getCurrentCycleIndex(), targetIndex); } } diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoMoveBackState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoMoveBackState.java similarity index 72% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoMoveBackState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoMoveBackState.java index 14b7152..783ab83 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoMoveBackState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoMoveBackState.java @@ -1,26 +1,25 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.datasource.database.surveyorrecord.SurveyorRecord; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.FindTargetMethod; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.IdUtil; - import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.FindTargetMethod; +import com.bingce.controlnetwork.util.IdUtil; + /** * 移动到上一测量结点,伴随删除上次测量数据 */ public class _DoMoveBackState extends __BaseState { - public _DoMoveBackState(StateManager stateManager) { + public _DoMoveBackState(StateManagerTj stateManager) { super(StateType.doMoveBack, stateManager); } @@ -39,11 +38,11 @@ public class _DoMoveBackState extends __BaseState { //如果测量结束,直接使用0号点盘右 int targetIndex = 0; LeftOrRight targetState = LeftOrRight.right; - warningWithStandStill(cachedDataSource, currentCycle, targetIndex, targetState); + warningWithStandStill(currentCycle, targetIndex, targetState); return; } String currentPointId = cachedDataSource.pointId(currentCycle, currentIndex); - String currentRecordKey = IdUtil.createSurveyorRecordId(stationId(), currentCycle, currentPointId, leftOrRight); + String currentRecordKey = IdUtil.surveyorRecordKey(stationId(), currentCycle, currentPointId, leftOrRight); DataCategory dataCategory = cachedDataSource.valueState(currentRecordKey); if (dataCategory.isNeedResurvey()) {//如果当前位置是脏数据(说明正在补测) //回退到上一个脏数据位置 @@ -72,7 +71,7 @@ public class _DoMoveBackState extends __BaseState { //找到dirtyAndSurveyed数据, //则将其校正为dirtyAndNeedReSurveyor String pointId = cachedData.pointId(target.cycleIndex, target.itemIndex); - String recordKey = IdUtil.createSurveyorRecordId(stationId(), target.cycleIndex, pointId, target.leftOrRight); + String recordKey = IdUtil.surveyorRecordKey(stationId(), target.cycleIndex, pointId, target.leftOrRight); SurveyorRecord surveyorRecord = cachedData.getSurveyorRecord(recordKey); if (surveyorRecord != null) { if (surveyorRecord.value1Status.isResurveyed()) { @@ -103,32 +102,42 @@ public class _DoMoveBackState extends __BaseState { DataCategory.normalCategory(), cachedData); if (target == null) { - failureTipsWithAutoStandStill(getContext().getString(R.string.tips_no_more_record_2_rollback)); + failureTipsWithAutoStandStill(getContext().getString(R.string.tips_no_more_record_2_rollback), null); return; } - warningWithStandStill(cachedData, + warningWithStandStill( currentCycle, target.itemIndex, target.leftOrRight); } private void warningWithStandStill( - ICachedData cachedDataSource, int currentCycle, int itemIndex, LeftOrRight leftOrRight) { optionTipsWithStandStill(getContext().getString(R.string.tips_will_resurvey_last_record), () -> { - //删除当前数据 - cachedDataSource.deleteSurveyorRecord(stationId(), - currentCycle, itemIndex, leftOrRight); - //重置进度 - setSingleCycleSchedule(currentCycle, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - - resetSchedule(this, itemIndex, leftOrRight); + if (currentCycle == 0) { + deleteLearnBaseData(measureWhat(), stationId(), getCachedData().pointId(currentCycle, itemIndex), () -> { + deleteCurrentPointData(currentCycle, itemIndex, leftOrRight); + }); + } else { + deleteCurrentPointData(currentCycle, itemIndex, leftOrRight); + } }); } + private void deleteCurrentPointData(int currentCycle, int itemIndex, LeftOrRight leftOrRight) { + //删除当前数据 + getCachedData().deleteSurveyorRecord(stationId(), + currentCycle, itemIndex, leftOrRight); + + //重置进度 + setStationScheduleForSingleCycle(currentCycle, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + + resetSchedule(this, itemIndex, leftOrRight); + } + private static void resetSchedule(__BaseState state, int targetIndex, LeftOrRight leftOrRight) { @@ -136,8 +145,8 @@ public class _DoMoveBackState extends __BaseState { state.setSurveyPosition(targetIndex, leftOrRight); //清除测量状态,进入idle //如果当前已经关闭自动测量,就不重置自动测量开关(用户已经表示不想自动测量) - state.enterIdleAndClearSurveyStateAndResetAutoMode(!state.isAutoSurveyClosed()); + state.enterIdleAndClearSurveyStateAndResetAutoMode(true); - state.scroll2(targetIndex); + state.scroll2(state.getCurrentCycleIndex(), targetIndex); } } diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoRecordCleanState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoRecordCleanState.java new file mode 100644 index 0000000..aa10e54 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoRecordCleanState.java @@ -0,0 +1,44 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; + +/** + * 记录测量数据 + */ +class _DoRecordCleanState extends __BaseState { + public _DoRecordCleanState(StateManagerTj stateManager) { + super(StateType.doRecordClean, stateManager); + } + + @Override + public void enter(Bundle args) { + ICachedData cacheData = getCachedData(); + ISurveyorData surveyorDataSource = getSurveyorData(); + ICycleRecorder cycleRecorder = getCycleRecorder(); + //设置数据正常 + surveyorDataSource.setDataCategory(DataCategory.normalCategory()); + //存储(缓存+数据库) + cacheData.cache(measureWhat(), cycleRecorder.currentCycleIndex(), surveyorDataSource, new ICachedData.CallBackCache() { + @Override + public void success() { + goToIsSingleCycleCompletedState(); + } + + @Override + public void failure() { + goToIsSingleCycleCompletedState(); + } + }); + } + + private void goToIsSingleCycleCompletedState() { + //检测单测回是否完成 + navigation2(StateType.isSingleCycleCompleted); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoSurveyorState.java similarity index 68% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoSurveyorState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoSurveyorState.java index f018210..f9c2425 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoSurveyorState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoSurveyorState.java @@ -1,57 +1,48 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.widget.Toast; import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.SurveyStateEvent; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorListener; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorRemindListener; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParam; -import com.bingce.controlapphelper.util.DebugMsgUtil; -import com.bingce.controlapphelper.util.IdUtil; -import com.bingce.controlapphelper.util.SettingValueUtil; import com.bingce.controlapphelper.util.SurveyorCycleUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.surveyor.state.StateConstants; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.surveyor.surveyor.RequestParam; +import com.bingce.controlnetwork.util.IdUtil; import com.bingce.device.Device; import com.bingce.totalstation.TotalStation; -import com.bingce.totalstation.protocol.south.SouthAndroidBtInterface; import com.bingce.totalstation.protocol.topcon.TopconInterface; import net.tatans.tensorflowtts.tts.TtsManager; -import blankj.utilcode.util.ToastUtils; /** * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 */ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurveyorRemindListener { private final ISurveyState surveyState; - //最多测量次数,如果3次测量都没有获取正常数据,则跳过 + //最多测量次数,如果5次测量都没有获取正常数据,则跳过 private static final int MAX_SURVEYOR_COUNT = 3; private static int failureCount = 0; private static final int RESULT_SUCCESS = 0; - private static final int RESULT_FAILURE_EXCEED_MAX = 1;//测量失败次数超出最大限制 - private static final int RESULT_FAILURE_ERROR = 2;//测量失败,又没有允许重复尝试 + private static final int RESULT_FAILURE_EXCEED_MAX = 1;//测量失败次数超出最大限制 key + private static final int RESULT_FAILURE_ERROR = 2;//测量失败,又没有允许重复尝试 key private static final boolean allowTryWhenFailure = true;//在测量失败的时候,是否允许重新测量 - private int measureTimeIndex = 0;//当前测点是第几次测量 + private int surveyorIndex = 0; private boolean isAlreadyRemindUserAimingAtWire = false; - private final Handler handler; + private Handler handler; - public _DoSurveyorState(StateManager stateManager, ISurveyState surveyState) { + public _DoSurveyorState(StateManagerTj stateManager, ISurveyState surveyState) { super(StateType.doSurveyor, stateManager); this.surveyState = surveyState; handler = new Handler(Looper.getMainLooper()); @@ -59,11 +50,10 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey @Override public void enter(Bundle args) { - measureTimeIndex = 0; - + surveyorIndex = 0; isAlreadyRemindUserAimingAtWire = false; if (args != null) { - isAlreadyRemindUserAimingAtWire = args.getBoolean(StateConstants.KEY_IS_ROTATION_READY_STATE); + isAlreadyRemindUserAimingAtWire = args.getBoolean(StateConstantsTj.KEY_IS_ALREADY_REMIND_USER_AIMING_AT_WIRE); } ToleranceDetailRecord toleranceRecord = getToleranceRecord(); @@ -71,7 +61,7 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey ICachedData cachedDataSource = getCachedData(); int currentCycleIndex = cycleRecorder.currentCycleIndex(); - int cycleCount = toleranceRecord.getCycleCount(); + int cycleCount = getCycleCount(); int pointCount = cachedDataSource.pointCount(); int otherCycle = -1; @@ -83,7 +73,7 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey //遍历该测回内所有点,检测是否有测量数据 for (int itemIndex = 0; itemIndex < pointCount; itemIndex++) { String pointId = cachedDataSource.pointId(cycleIndex, 0); - String key = IdUtil.createSurveyorRecordId(stationId(), cycleIndex, pointId, LeftOrRight.left); + String key = IdUtil.surveyorRecordKey(stationId(), cycleIndex, pointId, LeftOrRight.left); //检测该测回是否有数据,目前应该只需要检测盘左0就可以了,因为一个测回内数据不能跳过 DataCategory dataCategory = cachedDataSource.valueState(key); if (dataCategory.hasData()) { @@ -104,9 +94,9 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey if (otherCycle != -1) { final int targetCycleIndex = otherCycle; optionTipsWithStandStill( - SurveyorCycleUtil.cycleName(otherCycle) + Tools.getString(R.string.unfinished_measurements_starting_this_measurement_will_delete), + SurveyorCycleUtil.cycleName(otherCycle) + "有未完成测量,开始本次测量将删除其数据,是否继续?", () -> optionTipsWithStandStill( - Tools.getString(R.string.confirm_delete) + SurveyorCycleUtil.cycleName(targetCycleIndex) + Tools.getString(R.string.data_ask), + "确定删除" + SurveyorCycleUtil.cycleName(targetCycleIndex) + "数据?", () -> { String stationId = stationId(); //删除数据 @@ -127,7 +117,7 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey //判断设备是否连接 if (surveyorImpl().isReady()) { //发送测量信号 - SurveyStateEvent.postSurveying(positionFragment); + SurveyStateEvent.postSurveying(); //注册接收测量数据 surveyorImpl().prepareSurveyor(); sendSurveyRequest(); @@ -137,66 +127,32 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey } } - @Override - public void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { - //重置错误读数 - failureCount = 0; - if (getSurveyorData().onSurveyor(originalHa, originalVa, sd, hd)) { - //测量数据成功,可以退出测量状态 - onSuccess(); - } else {//测量数据不完全,需要继续测量 - measureTimeIndex = 1;//更新测量索引 - refreshUI(); - - if (TotalStation.getInstance() instanceof TopconInterface) { - //这个仪器需要延迟500毫秒发送指令 - handler.postDelayed(this::sendSurveyRequest, 500); - } else if (TotalStation.getInstance() instanceof SouthAndroidBtInterface) { - handler.postDelayed(this::sendSurveyRequest, 100); - } else { - sendSurveyRequest(); - } + private void sendSurveyRequestNext() { + if (isAutoSurveyOpen()) { + //当自动测量的时候继续发送测量指令 + sendSurveyRequestNextInner(); + } else { + //进入idle + navigation2(StateType.idle); } } - @Override - public void onError(String errorMsg) { - TtsManager.getInstance().speak(errorMsg); - if (allowTryWhenFailure) {//允许重新测量 - if (!isLive()) { - return; - } - //测量出现异常,需要处理 - failureCount++; - if (failureCount >= MAX_SURVEYOR_COUNT) { - if (isAutoSurveyOpen()) { - TtsManager.getInstance().speak(Tools.getString(R.string.many_measure_failed)); - } - onCompleted(RESULT_FAILURE_EXCEED_MAX, Tools.getString(R.string.many_measure_failed_1)); - } else { - //再次尝试 - DebugMsgUtil.canWrite("仪器返回错误信息:" + errorMsg); - DebugMsgUtil.canWrite("开始再次测量"); - - sendSurveyRequest(); - ToastUtils.showShort(R.string.receive_data_time_out); - } + private void sendSurveyRequestNextInner() { + if (TotalStation.getInstance() instanceof TopconInterface) { + //这个仪器需要延迟500毫秒发送指令 + handler.postDelayed(this::sendSurveyRequest, 500); } else { - onCompleted(RESULT_FAILURE_ERROR, errorMsg); + sendSurveyRequest(); } } private void sendSurveyRequest() { - int currentIndex = getCurrentIndex(); - if (currentIndex < 0) { - currentIndex = 0; + int surveyorPointIndex = getCurrentItemIndex(); + if (surveyorPointIndex < 0) { + surveyorPointIndex = 0; } - - SurveyorPoint surveyorPoint = getCachedData().getSurveyorPoint(getCycleRecorder().currentCycleIndex(), currentIndex); - ISurveyorData surveyorData = getSurveyorData(); - - surveyorImpl().requestSurveyor(new RequestSurveyorParam(getRequestSurveyorParamAuto(), getInstrumentHeight(), surveyorPoint, measureTimeIndex, - surveyorData.currentIndex(), surveyorData.leftOrRight(), isAlreadyRemindUserAimingAtWire)); + SurveyorPoint surveyorPoint = getCachedData().getSurveyorPoint(getCycleRecorder().currentCycleIndex(), surveyorPointIndex); + surveyorImpl().requestSurveyor(new RequestParam(measureWhat(), isAlreadyRemindUserAimingAtWire, isWellSteel(), isAloneMeasureDistancePoint(), surveyorIndex, surveyorPointIndex, surveyorPoint)); } private void onSuccess() { @@ -210,17 +166,19 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey case RESULT_SUCCESS://进入读数检测状态 //检测是否处于「自动测量」 if (!surveyState.isAutoSurveying()) { - SurveyStateEvent.postSuccess(positionFragment); + SurveyStateEvent.postSuccess(); } navigation2(StateType.checkReadData); break; case RESULT_FAILURE_EXCEED_MAX: -// if (SettingValueUtil.isAbandonPoint() && isAllowAbandonForVarifyIndex()) { +// boolean allowAbandon = App.getApp().isAllowSkip; +// if (allowAbandon && isAllowAbandonForVarifyIndex()) { // dealErrorDataSkip(msg); // } else { // dealErrorDataNormal(msg); // } dealErrorDataNormal(msg); + break; case RESULT_FAILURE_ERROR: dealErrorDataNormal(msg); @@ -249,25 +207,23 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey } private void dealErrorDataNormal(String msg) { - SurveyStateEvent.postFailure(positionFragment); + SurveyStateEvent.postFailure(); //进入失败状态 Bundle args = _SurveyorFailureState.args(msg); navigation2(StateType.SurveyorFailure, args); } private void dealErrorDataNormal(String msg, boolean isShowDialog) { - SurveyStateEvent.postFailure(positionFragment); + SurveyStateEvent.postFailure(); //进入失败状态 Bundle args = _SurveyorFailureState.args(msg, isShowDialog); navigation2(StateType.SurveyorFailure, args); } private void dealErrorDataSkip(String msg) { - optionTipsCountDown(msg + Tools.getString(R.string.is_it_abandoned), - Tools.getString(R.string.switch_abandon), - Tools.getString(R.string.ignore), + optionTipsCountDown(msg + ",是否废弃?", "废弃", "忽略", () -> { - changeSkip(getCycleRecorder().currentCycleIndex(), getCurrentIndex()); + changeSkip(getCycleRecorder().currentCycleIndex(), getCurrentItemIndex()); navigation2(StateType.isSingleCycleCompleted); }, () -> dealErrorDataNormal(msg, false), @@ -283,7 +239,7 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey boolean autoClose = getStation().isAutoClose(); int pointCount = getCachedData().pointCount(); boolean abandon = true; - int currentIndex = getCurrentIndex(); + int currentIndex = getCurrentItemIndex(); if (autoClose) { if (currentIndex == 0 || currentIndex == pointCount - 1) { abandon = false; @@ -295,4 +251,51 @@ class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurvey } return abandon; } + + @Override + public void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + //重置错误读数 + failureCount = 0; + if (getSurveyorData().onSurveyor(originalHa, originalVa, sd, hd)) { + //测量数据成功,可以退出测量状态 + onSuccess(); + } else {//测量数据不完全,需要继续测量 + surveyorIndex = 1;//更新测量索引 + refreshUI(); + if (checkLeftNot(true)) { + return; + } + if (isAlreadyRemindUserAimingAtWire) { + navigation2(StateType.idle); + return; + } + sendSurveyRequestNext(); + } + } + + @Override + public void onError(String errorMsg) { + TtsManager.getInstance().speak(errorMsg); + if (allowTryWhenFailure) {//允许重新测量 + if (!isLive()) { + return; + } + //测量出现异常,需要处理 + failureCount++; + if (failureCount >= MAX_SURVEYOR_COUNT) { + if (isAutoSurveyOpen()) { + TtsManager.getInstance().speak("多次测量未成功,已暂停,请检查"); + } + onCompleted(RESULT_FAILURE_EXCEED_MAX, "多次尝试测量未能成功"); + } else { + //再次尝试 + sendSurveyRequest(); + Toast.makeText(getContext(), "接收数据超时,再次尝试测量", Toast.LENGTH_SHORT).show(); + } + } else { + onCompleted(RESULT_FAILURE_ERROR, errorMsg); + } + } } + + diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoWellMeasureRotationReadyState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoWellMeasureRotationReadyState.java new file mode 100644 index 0000000..2c1ccb3 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_DoWellMeasureRotationReadyState.java @@ -0,0 +1,34 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; + +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.event.SurveyStateEvent; + +import net.tatans.tensorflowtts.tts.TtsManager; + +/** + * 钢丝测量旋转到位状态 + */ +class _DoWellMeasureRotationReadyState extends __BaseState { + + public _DoWellMeasureRotationReadyState(StateManagerTj stateManager) { + super(StateType.doWellMeasureRotationReady, stateManager); + } + + @Override + public void enter(Bundle args) { + // TODO: 2024/8/30 +// String msg; +// if (isWellSteel()) { +// msg = getContext().getString(R.string.please_aiming_at_wire_then_measure); +// } else if (isAloneMeasureDistancePoint()) { +// msg = getContext().getString(R.string.please_aiming_at_no_prism_then_measure); +// } else { +// msg = "请瞄准目标" + getCachedData().pointName(getCurrentCycleIndex(), getCurrentItemIndex()) + "后,再次点击开始测量"; +// } +// runOnUI(() -> TtsManager.getInstance().speak(msg)); + SurveyStateEvent.postIdle(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IdleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IdleState.java new file mode 100644 index 0000000..fcb4328 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IdleState.java @@ -0,0 +1,251 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.os.Bundle; +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.event.AutoSurveyorButtonVisibleEvent; +import com.bingce.controlnetwork.event.RefreshRollBackEvent; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.FindTargetMethod; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.totalstation.ControlSurveyResult; + +import org.greenrobot.eventbus.EventBus; + +/** + * 空闲状态 + *

+ * 将刷新界面 + */ +class _IdleState extends __BaseState { + private final @NonNull + IAutoModeSwitcher autoModeSwitcher; + + public _IdleState(StateManagerTj stateManager, @NonNull IAutoModeSwitcher autoModeSwitcher) { + super(StateType.idle, stateManager); + this.autoModeSwitcher = autoModeSwitcher; + } + + @Override + public void enter(Bundle args) { + //1.刷新界面 + refreshUI(); + //2.检测是否有数据,来控制goBack + refreshGoBackButton(); + + //3.当前cycle是否完成测量 + boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( + stationId(), + getCycleRecorder().currentCycleIndex(), + getCachedData()); + //4.检测是否满足自动测量条件 + //判断当前条件是否满足自动测量 + autoModeSwitcher.isReadyAutoSurvey(isReadyCode -> { + boolean isReady = isReadyCode == ControlSurveyResult.CODE_SUCCESS; + + boolean isAutoSurveyOpen = false; + + if (autoModeSwitcher.isAutoModeOpen() && isReady) {//如果打开着自动测量,且满足条件 + if (isLive()) { + Log.d("hwhw", "从空闲状态进入测量状态"); + navigation2(StateType.doSurveyor); + isAutoSurveyOpen = true; + } else { + autoModeSwitcher.resetAutoMode(); + } + //发送通知,更新测量按钮UI + postEvent(true, isAutoSurveyOpen, completed); + } else if (autoModeSwitcher.isAutoModeInit() && isReady && !completed) {//自动测量状态为unknown,弹框提示用户选择 + //用户选择后会发送通知,更新测量按钮UI + tips4StartAutoSurvey(); + } else if (ControlSurveyResult.isAbandon(isReadyCode) != null) { + String msg = ControlSurveyResult.isAbandon(isReadyCode); + runOnUI(() -> { + optionTipsCountDown(msg + ",是否废弃?", "废弃", "重测", + () -> { + boolean success = dealSkip(); + if (!success) { + resetSurveyForReadyAndComplete(isReady, completed); + } + }, + () -> { + boolean success = reMeasure(); + if (!success) { + resetSurveyForReadyAndComplete(isReady, completed); + } + }, + () -> resetSurveyForReadyAndComplete(isReady, completed)); + }); + } else { + resetSurveyForReadyAndComplete(isReady, completed); + } + }); + + } + + /** + * 弹框提示用户是否开启自动测量 + */ + private void tips4StartAutoSurvey() { +// runOnUI(() -> +// TipsWith2OptionFragment.tips( +// fragmentManager(), +// lifecycleOwner(), +// getContext().getString(R.string.hint), +// null, +// null, +// null, +// getContext().getString(R.string.tips_finish_study_should_auto_survey), +// -1, +// false, +// new TipsWith2OptionFragment.SimpleCallback() { +// @Override +// public void onConfirm() { +// TtsManager.getInstance().speak("开始自动测量"); +// autoModeSwitcher.openAutoMode(); +// navigation2(StateType.doSurveyor); +// +// postEvent(true, true, false); +// } +// +// @Override +// public void onCancel() { +// autoModeSwitcher.closeAutoMode(); +// +// postEvent(true, false, false); +// } +// +// @Override +// public void onIgnore() { +// autoModeSwitcher.closeAutoMode(); +// +// postEvent(true, false, false); +// } +// } +// )); + } + + private static void postEvent(boolean isReadyAutoSurvey, boolean isOpenAutoSurvey, boolean isSingleCompleted) { + EventBus.getDefault().post(new AutoSurveyorButtonVisibleEvent(isReadyAutoSurvey, isOpenAutoSurvey)); + if (isSingleCompleted) { + SurveyStateEvent.postCompleted(); + } else if (!isOpenAutoSurvey) { + SurveyStateEvent.postIdle(); + } + } + + @Override + protected void resume() { + autoModeSwitcher.resetAutoMode(); + //刷新测量按钮 + boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( + stationId(), + getCycleRecorder().currentCycleIndex(), + getCachedData()); + + autoModeSwitcher.isReadyAutoSurvey(code -> { + boolean isReady = code == ControlSurveyResult.CODE_SUCCESS; + postEvent(isReady, false, completed); + }); + } + + private void resetSurveyForReadyAndComplete(boolean isReady, boolean completed) { + //如果自动测量打开了,但是没有进入测量状态 + //需要将自动测量开关重置 + if (autoModeSwitcher.isAutoModeOpen()) { + autoModeSwitcher.resetAutoMode(); + } + //发送通知,更新测量按钮UI + postEvent(isReady, false, completed); + } + + private boolean reMeasure() { + FindTargetMethod.Target target = findLastTarget(); + if (target == null) { + return false; + } + + ICachedData cachedData = getCachedData(); + + cachedData.deleteSurveyorRecord(stationId(), target.cycleIndex + , target.itemIndex, target.leftOrRight); + //重置进度 + setStationScheduleForSingleCycle(target.cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + + //设置测量目标点 + setSurveyPosition(target.itemIndex, target.leftOrRight); + scroll2(getCurrentCycleIndex(), target.itemIndex); + refreshUI(); + + navigation2(StateType.doSurveyor); + + return true; + } + + private boolean dealSkip() { + FindTargetMethod.Target lastTarget = findLastTarget(); + if (lastTarget == null) { + return false; + } + changeSkip(getCycleRecorder().currentCycleIndex(), lastTarget.itemIndex); + navigation2(StateType.isSingleCycleCompleted); + return true; + } + + private FindTargetMethod.Target findLastTarget() { + ICachedData cachedData = getCachedData(); + ISurveyorData surveyorDataSource = getSurveyorData(); + ICycleRecorder cycleRecorder = getCycleRecorder(); + + final int pointCount = cachedData.pointCount(); + final int currentCycle = cycleRecorder.currentCycleIndex(); + final int currentIndex = surveyorDataSource.currentIndex(); + final LeftOrRight leftOrRight = surveyorDataSource.leftOrRight(); + + if (currentIndex < 0) { + return null; + } + + String currentPointId = cachedData.pointId(currentCycle, currentIndex); + String currentRecordKey = IdUtil.surveyorRecordKey(stationId(), currentCycle, currentPointId, leftOrRight); + DataCategory dataCategory = cachedData.valueState(currentRecordKey); + + DataCategory dataCategoryLook = null; + if (dataCategory.isNeedResurvey()) {//如果当前位置是脏数据(说明正在补测) + //回退到上一个脏数据位置 + dataCategoryLook = DataCategory.dirtyAndSurveyed; + } else if (dataCategory.isEmptyData()) { + dataCategoryLook = DataCategory.normalCategory(); + } + + if (dataCategoryLook == null) { + return null; + } + + return FindTargetMethod.findTargetInSingleCycle( + stationId(), currentCycle, currentIndex, leftOrRight, pointCount, false, + dataCategoryLook, + cachedData); + } + + private void refreshGoBackButton() { + int currentCycle = getCycleRecorder().currentCycleIndex(); + String pointId = getCachedData().pointId(currentCycle, 0); + DataCategory dataCategory = getCachedData().valueState( + IdUtil.surveyorRecordKey(stationId(), currentCycle, pointId, LeftOrRight.left), 0); + + int fragmentPosition = RefreshRollBackEvent.getFragmentPosition(measureWhat(), getStation().isSeparateObservation()); + + EventBus.getDefault().post(new RefreshRollBackEvent(!dataCategory.isEmptyData(), fragmentPosition)); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Is2CCheckReadyState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Is2CCheckReadyState.java similarity index 75% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Is2CCheckReadyState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Is2CCheckReadyState.java index 4b17c04..4275157 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Is2CCheckReadyState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_Is2CCheckReadyState.java @@ -1,14 +1,13 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.IdUtil; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.util.IdUtil; /** * 判断是否满足「2C」检测条件 @@ -17,7 +16,7 @@ class _Is2CCheckReadyState extends __BaseState { private static final int RESULT_YES = 0;//可以检测「2C」 private static final int RESULT_NO = 1;//不可以检测「2C」 - public _Is2CCheckReadyState(StateManager stateManager) { + public _Is2CCheckReadyState(StateManagerTj stateManager) { super(StateType.isReady2CCheck, stateManager); } @@ -35,7 +34,7 @@ class _Is2CCheckReadyState extends __BaseState { //当前位置正处于测量,数据还没有缓存,所以不需要检测数据合法性 String pointId = cachedData.pointId(currentCycleIndex, currentIndex); DataCategory oppositeCategory = cachedData.valueState( - IdUtil.createSurveyorRecordId(stationId(), currentCycleIndex, pointId, currentLeftOrRight.opposite())); + IdUtil.surveyorRecordKey(stationId(), currentCycleIndex, pointId, currentLeftOrRight.opposite())); if (oppositeCategory.isFreshData()) { onCompleted(RESULT_YES); } else { diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsAllCycleCompletedState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsAllCycleCompletedState.java similarity index 51% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsAllCycleCompletedState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsAllCycleCompletedState.java index 01a20e4..11a2f17 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsAllCycleCompletedState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsAllCycleCompletedState.java @@ -1,21 +1,12 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import androidx.annotation.NonNull; -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.config.ConfigConstants; -import com.bingce.controlapphelper.datasource.database.config.ConfigRecord; -import com.bingce.controlapphelper.datasource.database.config.IConfigDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.data.SpeakCache; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; import com.bingce.controlapphelper.util.SurveyorCycleUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.utils.ThreadPoolUtil; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.SpeakCache; import net.tatans.tensorflowtts.tts.TtsManager; @@ -28,14 +19,14 @@ public class _IsAllCycleCompletedState extends __BaseState { private static final int INVALIDATE_CYCLE = -1; private final IAutoModeSwitcher autoModeSwitcher; - public _IsAllCycleCompletedState(@NonNull StateManager stateManager, IAutoModeSwitcher autoModeSwitcher) { + public _IsAllCycleCompletedState(@NonNull StateManagerTj stateManager, IAutoModeSwitcher autoModeSwitcher) { super(StateType.isAllCycleCompleted, stateManager); this.autoModeSwitcher = autoModeSwitcher; } @Override public void enter(Bundle args) { - int cycleCount = getToleranceRecord().getCycleCount(); + int cycleCount = getCycleCount(); int theCycleNotAllDataIsValidate = INVALIDATE_CYCLE; //查找数据不全的测回 @@ -51,20 +42,14 @@ public class _IsAllCycleCompletedState extends __BaseState { if (completed) { if (isAutoSurveyOpen()) { - //检测是否已经提示 - //检测是否需要提示测站检测 - IConfigDataSource configDataSource = - SurveyorDatabaseFactory.instance.getConfigDataSource(); - ThreadPoolUtil.execute(() -> { - String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId(); - ConfigRecord record = configDataSource.getByKeySync(key); - if (record == null || ConfigConstants.VALUE_NO.equals(record.getConfigValue())) { - runOnUI(() -> TtsManager.getInstance().speak(Tools.getString(R.string.all_cycle_completed))); - } - }); +// //检测是否已经提示 +// //检测是否需要提示测站检测 +// IConfigDataSource configDataSource = +// SurveyorDatabaseFactory.instance.getConfigDataSource(); + runOnUI(() -> TtsManager.getInstance().speak("所有测回已完成")); } //标识测站完成测量(数据库存储) - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); //进入idle状态 //清除测量状态,进入测站检测,停止自动测量 enterStationCheckAndClearSurveyStateAndResetAutoMode(); @@ -74,13 +59,13 @@ public class _IsAllCycleCompletedState extends __BaseState { //切换测回 getCycleRecorder().changeCycleIndex(theCycleNotAllDataIsValidate); //修改当前测回 - setCurrentCycle(theCycleNotAllDataIsValidate); + setStationCycle(theCycleNotAllDataIsValidate); //存储一下已经播放切换测回的的节点 SpeakCache.getInstance().saveSpeakSwitchCycle(); //查找测量目标 findTargetFromBeginInCurrentCycle(false); //播报 - TtsManager.getInstance().speak(Tools.getString(R.string.current_cycle_complete_start_surveyor) + SurveyorCycleUtil.cycleName(theCycleNotAllDataIsValidate)); + TtsManager.getInstance().speak("当前测回已完成,开始测量" + SurveyorCycleUtil.cycleName(theCycleNotAllDataIsValidate)); } else { //提示是否进入其他未完成测回继续测量 option4Jump2OtherEmptyCycle(theCycleNotAllDataIsValidate); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsHalfCycleZeroCheckReadyState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsHalfCycleZeroCheckReadyState.java similarity index 81% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsHalfCycleZeroCheckReadyState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsHalfCycleZeroCheckReadyState.java index cfdc465..efc0a8f 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsHalfCycleZeroCheckReadyState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsHalfCycleZeroCheckReadyState.java @@ -1,14 +1,14 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.IdUtil; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.util.IdUtil; + /* * 判断是否需要检测「半测回归零差」 @@ -18,7 +18,7 @@ class _IsHalfCycleZeroCheckReadyState extends __BaseState { private static final int RESULT_YES = 0;//可以检测「半测回归零差」 private static final int RESULT_NO = 1;//不可以检测「半测回归零差」 - public _IsHalfCycleZeroCheckReadyState(StateManager stateManager) { + public _IsHalfCycleZeroCheckReadyState(StateManagerTj stateManager) { super(StateType.isHalfCycleZeroCheckReady, stateManager); } @@ -42,7 +42,7 @@ class _IsHalfCycleZeroCheckReadyState extends __BaseState { int targetIndex = pointCount - 1 - currentItemIndex; String targetPointId = cachedData.pointId(cycleRecorder.currentCycleIndex(), targetIndex); - String targetKey = IdUtil.createSurveyorRecordId(stationId, cycleIndex, targetPointId, leftOrRight); + String targetKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, targetPointId, leftOrRight); DataCategory targetDataCategory = cachedData.valueState(targetKey); //对面数据正常,可以执行半测回归零 if (targetDataCategory.isFreshData()) { diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsSingleCycleCompletedState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsSingleCycleCompletedState.java similarity index 72% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsSingleCycleCompletedState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsSingleCycleCompletedState.java index e54e20c..4d482ef 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IsSingleCycleCompletedState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_IsSingleCycleCompletedState.java @@ -1,20 +1,19 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.IdUtil; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.util.IdUtil; public class _IsSingleCycleCompletedState extends __BaseState { private static final int RESULT_YES = 0;//测回结束 private static final int RESULT_NO = 1;//测回未结束 - public _IsSingleCycleCompletedState(StateManager stateManager) { + public _IsSingleCycleCompletedState(StateManagerTj stateManager) { super(StateType.isSingleCycleCompleted, stateManager); } @@ -34,7 +33,7 @@ public class _IsSingleCycleCompletedState extends __BaseState { int cycleIndex = getCycleRecorder().currentCycleIndex(); //更新测回测量进度 - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); //状态切换 navigation2(StateType.checkSingleCycle); } else { @@ -51,14 +50,14 @@ public class _IsSingleCycleCompletedState extends __BaseState { //测回内所有数据都是「新鲜数据」才能执行「测回内检测」 for (int index = 0; index < cachedData.pointCount(); index++) { - if (cachedData.isPointAbandon(cycleIndex, index)) { + if (cachedData.isAbandonPoint(cycleIndex, index)) { continue; } String pointId = cachedData.pointId(cycleIndex, index); - String leftKey = IdUtil.createSurveyorRecordId(stationId, cycleIndex, pointId, LeftOrRight.left); - String rightKey = IdUtil.createSurveyorRecordId(stationId, cycleIndex, pointId, LeftOrRight.right); + String leftKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + String rightKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right); DataCategory leftDataCategory = cachedData.valueState(leftKey); DataCategory rightDataCategory = cachedData.valueState(rightKey); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_SurveyorFailureState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_SurveyorFailureState.java similarity index 71% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_SurveyorFailureState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/_SurveyorFailureState.java index 9135bf6..e309a6e 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_SurveyorFailureState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/_SurveyorFailureState.java @@ -1,19 +1,15 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; +package com.bingce.controlnetwork.surveyor.state; import android.os.Bundle; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; - /* * 仪器导致的测量失败 * * 全站仪多次测量失败,进入该状态 * */ -class _SurveyorFailureState extends __BaseState { +public class _SurveyorFailureState extends __BaseState { - public _SurveyorFailureState(StateManager stateManager) { + public _SurveyorFailureState(StateManagerTj stateManager) { super(StateType.SurveyorFailure, stateManager); } @@ -27,7 +23,7 @@ class _SurveyorFailureState extends __BaseState { } if (isShowDialog) { - failureTipsWithAutoStandStill(error + Tools.getString(R.string.please_observe_target)); + failureTipsWithAutoStandStill(error + ",请重新观测该目标.", null); } else { enterIdleAndClearSurveyStateAndResetAutoMode(true); } diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/__BaseState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/__BaseState.java new file mode 100644 index 0000000..f5b53f6 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/__BaseState.java @@ -0,0 +1,306 @@ +package com.bingce.controlnetwork.surveyor.state; + +import android.util.Log; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.util.SurveyorCycleUtil; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.fragment.TipsFragment; +import com.bingce.controlnetwork.surveyor.method.model.IStateDelegate; +import com.bingce.controlnetwork.surveyor.state.base.AbstructState; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.totalstation.TotalStation; + +import java.util.List; + +import blankj.utilcode.util.ToastUtils; + + +public abstract class __BaseState extends AbstructState { + /** + * 判断常量 + */ + private final int DEFAULT_AUTO_MODE = 0; + private final int RESET_AUTO_MODE = 1; + private final int CLOSE_AUTO_MODE = 2; + + public __BaseState(final StateType stateType, final StateManagerTj stateManager) { + super(stateType, stateManager); + } + + + /** + * 设置测量位置 + */ + @Override + protected void setSurveyPosition(int index, LeftOrRight leftOrRight) { + getSurveyorData().setCurrentIndex(index); + getSurveyorData().setLeftOrRight(leftOrRight); + + int currentCycleIndex = getCycleRecorder().currentCycleIndex(); + //新增 + boolean wellSteelPoint = getCachedData().isWellSteelPoint(currentCycleIndex, index); + if (wellSteelPoint) + ToastUtils.showShort("钢丝点"); + } + + final protected void failureTipsWithAutoStandStill(String msg, Runnable runnable) { + if (!isLive()) { + return; + } + TipsFragment.noCancelAbleTips(fragmentManager(), lifecycleOwner(), + getContext(), + msg, + -1, + () -> { + if (runnable != null) { + runnable.run(); + } + enterIdleAndClearSurveyStateAndResetAutoMode(true); + }); + } + + final protected void optionTipsWithStandStill(String msg, Runnable confirmCallback) { + optionTips(msg, null, null, + confirmCallback, + () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), + () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); + } + + /** + * 提供选择操作 + * 如果用户选择忽略,则自动保持原地不动,进入idle状态 + */ + final protected void optionTipsWithStandStill( + String msg, String confirmButton, String cancelButton, Runnable confirmCallback) { + optionTips(msg, confirmButton, cancelButton, + confirmCallback, + () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), + () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); + } + + + protected final void option4Jump2OtherCycle4Resurvey(int cycleIndex) { + option4Jump2OtherCycle(cycleIndex, true); + } + + protected final void option4Jump2OtherEmptyCycle(int cycleIndex) { + option4Jump2OtherCycle(cycleIndex, false); + } + + private void option4Jump2OtherCycle(int cycleIndex, boolean resurveyOrEmpty) { + String msg = "有待测数据,是否跳转到该处继续."; + if (resurveyOrEmpty) { + msg = "有待补测数据,是否跳转到该处继续."; + } + optionTips("在" + SurveyorCycleUtil.cycleName(cycleIndex) + msg, + null, + null, + () -> { + //切换测回 + getCycleRecorder().changeCycleIndex(cycleIndex); + //数据库存储修改当前测回 + setStationCycle(cycleIndex); + //查找测量目标 + findTargetFromBeginInCurrentCycle(false); + }, + () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), + () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); + } + + + @Override + final protected void setStationCycle(int cycle) { + getCycleRecorder().changeCycleIndex(cycle); + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), stateManager.getMeasureWhat()), + String.valueOf(cycle))); + } + + @Override + final protected void setStationScheduleForSingleCycle(int cycleIndex, String statue) { + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationSingleCycleScheduleKey(stationId(), stateManager.getMeasureWhat(), cycleIndex), + statue)); + } + + @Override + final protected void setStationScheduleForAllCycle(String statue) { + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationAllCycleScheduleKey(stationId(), stateManager.getMeasureWhat()), + statue)); + } + + /** + * 如果resetAutoSurveyState为true,将重置autoSurvey状态为unknown + */ + final protected void findTargetFromBeginInCurrentCycle(boolean resetAutoSurveyState) { + getSurveyorData().clearSurveyStateAndPosition(); + if (resetAutoSurveyState) { + autoModeRecorder().resetAutoMode(); + } + navigation2(StateType.doMove2NextValidate); + } + + final protected void enterIdleAndClearSurveyState() { + clearSurveyStateAndCloseAutoModeAndStandStill(DEFAULT_AUTO_MODE, + false, StateType.idle); + } + + /** + * 取消测量,会停在当前位置(索引+盘左or盘右),并进入idle + */ + final protected void enterIdleAndClearSurveyStateAndResetAutoMode(boolean resetAutoMode) { + clearSurveyStateAndCloseAutoModeAndStandStill(resetAutoMode ? RESET_AUTO_MODE : DEFAULT_AUTO_MODE, + false, StateType.idle); + } + + final protected void enterIdleAndClearSurveyorStatePosition() { + clearSurveyStateAndCloseAutoModeAndStandStill(DEFAULT_AUTO_MODE, + true, StateType.idle); + } + + final protected void enterStationCheckAndClearSurveyStateAndResetAutoMode() { + clearSurveyStateAndCloseAutoModeAndStandStill(RESET_AUTO_MODE, + false, StateType.checkStation); + } + + final protected void enterIdleAndClearSurveyStateAndCloseAutoMode() { + clearSurveyStateAndCloseAutoModeAndStandStill(CLOSE_AUTO_MODE, false, StateType.idle); + } + + /** + * @param autoMode + * @param clearPosition + * @param stateType + */ + private void clearSurveyStateAndCloseAutoModeAndStandStill(int autoMode, boolean clearPosition, StateType stateType) { + //重置或者关闭自动模式 + if (autoMode == RESET_AUTO_MODE) { + autoModeRecorder().resetAutoMode(); + } else if (autoMode == CLOSE_AUTO_MODE) { + autoModeRecorder().closeAutoMode(); + } + //更新测量进度标识 + if (clearPosition) { + getSurveyorData().clearSurveyStateAndPosition(); + } else { + getSurveyorData().clearSurveyState(); + } + //进入某个状态 + navigation2(stateType); + } + + + protected IStateDelegate stateDelegate() { + return new IStateDelegate() { + @Override + public void onOptionTips( + String msg, String confirmButton, String cancelButton, + Runnable confirmCallback, Runnable cancelCallback, Runnable ignoreCallback) { + optionTips( + msg, confirmButton, cancelButton, + confirmCallback, cancelCallback, ignoreCallback); + } + + @Override + public void resetSurveyorStateAndKeepPosition() { + //关闭自动测量 + autoModeRecorder().resetAutoMode(); + //更新测量进度标识 + getSurveyorData().clearSurveyState(); + //进入空闲状态 + navigation2(StateType.idle); + } + + @Override + public void resurveyPoints(int cycleIndex, List pointIds) { + if (cycleIndex == -1) { + cycleIndex = getCycleRecorder().currentCycleIndex(); + } + + //更新记录数据,包括将数据置为dirty和切换cycle + getCachedData().markReSurveyor(stationId(), cycleIndex, pointIds); + getCycleRecorder().changeCycleIndex(cycleIndex); + + //根据当前状态,查找一个目标 + findTargetFromBeginInCurrentCycle(true); + + //更新数据库标识 + setStationCycle(cycleIndex); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + } + + @Override + public void deleteSingleCycleData(int cycleIndex) { + //删除数据 + getCachedData().deleteSurveyorRecord(stationId(), cycleIndex); + //切换测回--一般不用,但是这里为了保险 + getCycleRecorder().changeCycleIndex(cycleIndex); + //查找一个新目标开启测量 + findTargetFromBeginInCurrentCycle(true); + + //更新数据库标识 + setStationCycle(cycleIndex); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForSingleCycle(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + } + }; + } + + + @Override + protected int getCycleCount() { + return StationUtilPla.getCycleCount(stateManager.getMeasureWhat(), getStation(), getToleranceRecord()); + } + + /** + * 如果是测回内首次测量,需要判断是否是盘左 + */ + protected boolean checkLeftNot(boolean isFirst) { + int currentItem = getSurveyorData().currentIndex(); + LeftOrRight leftOrRight = getSurveyorData().leftOrRight(); + if (currentItem == 0 && leftOrRight == LeftOrRight.left) { + //如果是首次测量,强制要求使用盘左 + double vAngle; + if (isFirst) { + vAngle = getSurveyorData().getAngleVer1(); + } else { + vAngle = getSurveyorData().getAngleVer(); + } + if (!isLeftVerAngle(vAngle)) { + failureTipsWithAutoStandStill( + getContext().getString(R.string.error_tips_please_start_from_left), + () -> { + Log.d("hwhw", "TotalStation.getInstance().requestChangeFace()"); + TotalStation.getInstance().requestChangeFace(); + }); + return true; + } + } + return false; + } + + + private boolean isLeftVerAngle(double vAngle) { + return vAngle >= 0 && vAngle <= Math.PI; + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/StateManagerAloneDistance.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/StateManagerAloneDistance.java deleted file mode 100644 index 1d05490..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/StateManagerAloneDistance.java +++ /dev/null @@ -1,498 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.content.Context; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.WorkerThread; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; -import com.bingce.controlapphelper.datasource.database.point.PointRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.RefreshGoBackButtonAloneDistance; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.AutoSurveyorMethod; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.IStateType; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyor; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorListener; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorRemindListener; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParamAuto; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorAutoImpl; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorMock; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorMockAuto; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorSingleImpl; -import com.bingce.controlapphelper.surveyor.test.Test; -import com.bingce.controlapphelper.util.DigitalUtil; -import com.bingce.controlapphelper.util.IUIRunner; -import com.bingce.controlapphelper.util.IdUtil; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureVm; -import com.bingce.controlnetwork.surveyor.state.AutoModeType; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.controlnetwork.surveyor.state.StateConstants; -import com.bingce.coordlib.model.Coordinate; -import com.bingce.totalstation.ControlSurveyData; -import com.bingce.totalstation.ControlSurveyResult; -import com.bingce.utils.ThreadPoolUtil; -import com.bingce.utils.VipManager; - -import org.greenrobot.eventbus.EventBus; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import blankj.utilcode.util.ToastUtils; - -public class StateManagerAloneDistance implements IAutoModeSwitcher, ISurveyState, IStateType { - - //单独测距代码里的cycleIndex只有一个测回 - public static final int CYCLE_INDEX_DEFAULT = 0; - - private final Map stateMap = new HashMap<>(); - private StateType currentStateType = StateType.idle; - private final FragmentManager fragmentManager; - private final LifecycleOwner lifecycleOwner; - private final IUIRunner iuiRunner; - final IScrollDelegate scrollDelegate; - - @NonNull - SurveyorStationRecord stationRecord; - @NonNull - final CachedDataAloneDistance cachedData; - final @NonNull - ToleranceDetailRecord toleranceRecord; - final @NonNull - ISurveyorData surveyorData; - final @NonNull - MeasureVm measureVm; - final @NonNull - ICycleRecorder cycleRecorder; - final @NonNull - Context context; - private AutoModeType autoMode = AutoModeType.unknown; - @NonNull - final ISurveyor surveyor; - final PointRecord stationPointRecord; - - final boolean supportAutoSurvey; - - - private StateManagerAloneDistance(final boolean supportAutoSurvey,//是否支持自动测量 - final @NonNull SurveyorStationRecord stationRecord, - final @NonNull PointRecord stationPointRecord, - final @NonNull ToleranceDetailRecord toleranceRecord, - final @NonNull Context context, - final @NonNull ISurveyorData surveyorData, - final @NonNull ICycleRecorder cycleRecorder, - final @NonNull CachedDataAloneDistance cachedData, - final @NonNull MeasureVm measureVm, - final @NonNull IScrollDelegate scrollDelegate, - FragmentManager fragmentManager, - LifecycleOwner lifecycleOwner, - IUIRunner iuiRunner) { - this.supportAutoSurvey = supportAutoSurvey; - - this.stationRecord = stationRecord; - this.stationPointRecord = stationPointRecord; - this.fragmentManager = fragmentManager; - this.lifecycleOwner = lifecycleOwner; - this.iuiRunner = iuiRunner; - this.scrollDelegate = scrollDelegate; - - this.context = context; - this.toleranceRecord = toleranceRecord; - this.surveyorData = surveyorData; - this.cachedData = cachedData; - this.measureVm = measureVm; - this.cycleRecorder = cycleRecorder; - - if (Test.DEBUG) { - surveyor = new SurveyorMockAuto(StateConstants.VALUE_MEASURE_WHAT_DISTANCE, - this.stationRecord.getId(), - this.stationRecord.isAutoClose(), - toleranceRecord.getCycleCount(), - cachedData, surveyorData, cycleRecorder, this, this); - } else { - if (supportAutoSurvey) { - surveyor = new SurveyorAutoImpl(StateConstants.VALUE_MEASURE_WHAT_DISTANCE, this); - } else { - surveyor = new SurveyorSingleImpl(StateConstants.VALUE_MEASURE_WHAT_DISTANCE); - } - } - _DoSurveyorState doSurveyorState = new _DoSurveyorState(this, this); - surveyor.register((ISurveyorListener) doSurveyorState); - surveyor.register((ISurveyorRemindListener) doSurveyorState); - - stateMap.put(StateType.doSurveyor, doSurveyorState); - stateMap.put(StateType.doAutoSurveyor, new _DoAutoSurveyorState(this, this)); - stateMap.put(StateType.SurveyorFailure, new _SurveyorFailureState(this)); - stateMap.put(StateType.doMove2NextValidate, new _DoMove2NextValidateState(this)); - stateMap.put(StateType.doMoveBack, new _DoMoveBackState(this)); - stateMap.put(StateType.checkReadData, new _CheckReadDataState(this, this)); - stateMap.put(StateType.isSingleCycleCompleted, new _IsSingleCycleCompletedState(this)); - stateMap.put(StateType.isAllCycleCompleted, new _IsAllCycleCompletedState(this, this)); - stateMap.put(StateType.checkSingleCycle, new _CheckSingleCycleState(this)); - stateMap.put(StateType.checkStation, new _CheckStationState(this)); - stateMap.put(StateType.stationCheckedSuccess, new _CheckStationSuccessState(this)); - - stateMap.put(StateType.doDeleteAllCycle, new _DoDeleteAllCycleState(this)); - stateMap.put(StateType.doDeleteCurrentCycle, new _DoDeleteCurrentCycleState(this)); - - stateMap.put(StateType.doCalScheduleSingleCycle, new _DoCalScheduleInSingleCycleState(this, this)); - stateMap.put(StateType.doCalAdjust, new _DoCalAdjustState(this)); - stateMap.put(StateType.idle, new _IdleState(this, this)); - stateMap.put(StateType.doWellMeasureRotationReady, new _DoWellMeasureRotationReadyState(this)); - - } - - public void updateStationRecord(SurveyorStationRecord stationRecord) { - this.stationRecord = stationRecord; - ThreadPoolUtil.execute(() -> { - cachedData.updateDataSouce(stationRecord); - if (Test.DEBUG && surveyor instanceof SurveyorMock) { - ((SurveyorMock) surveyor).updateData(); - } - _DoCalScheduleInSingleCycleState.enter(this, CYCLE_INDEX_DEFAULT); - - //最后刷新下页面 - runOnUI(cachedData::notifyDateChange); - }); - -// //更新测点棱镜信息 -// if (stationRecord.getItems() != null) { -// for (SurveyorPoint item : stationRecord.getItems()) { -// if (item == null || !SurveyorPoint.TYPE_POINT.equals(item.getType())) { -// continue; -// } -// cachedData.updateSurveyPointParams(item); -// } -// } - } - - String stationId() { - return stationRecord.getId(); - } - - @Override - public void enter(StateType type, Bundle args) { - __BaseState baseState = stateMap.get(type); - if (baseState != null) { - this.currentStateType = type; - runOnUI(() -> baseState.enter(args)); - } - } - - @Override - public void enter(StateType type) { - enter(type, null); - } - - void runOnUI(Runnable action) { - if (iuiRunner != null) { - iuiRunner.runOnUI(action); - } - } - - public void doSurveyor() { - boolean inValidate = isInValidate(); - - if (inValidate) { - return; - } - - int pointCount = cachedData.pointCount(); - if (pointCount == 0) { - ToastUtils.showShort(R.string.no_data_available_yet); - return; - } - - Bundle bundle = null; - if (isRotationReadyState()) { - //当前是旋转到位状态 - bundle = new Bundle(); - bundle.putBoolean(StateConstants.KEY_IS_ROTATION_READY_STATE, true); - } - - enter(StateType.doSurveyor, bundle); - - } - - private boolean isRotationReadyState() { - return currentStateType == StateType.doWellMeasureRotationReady; - } - - public void doAutoSurveyor() { - if (isInValidate()) { - return; - } - enter(StateType.doAutoSurveyor); - } - - /** - * 删除站的所有测回记录 - */ - public void deleteCurrentStationSurveyorData() { - if (isInValidate()) { - return; - } - enter(StateType.doDeleteAllCycle, _DoDeleteAllCycleState.args(stationId())); - } - - public void deleteCurrentStationSurveyorData(int cycleIndex) { - if (isInValidate()) { - return; - } - enter(StateType.doDeleteCurrentCycle, _DoDeleteCurrentCycleState.args(stationId(), cycleIndex)); - } - - public void stationCheck() { - if (isInValidate()) { - return; - } - enter(StateType.checkStation); - } - - public void stationAdjust() { - if (isInValidate()) { - return; - } - enter(StateType.doCalAdjust); - } - - /** - * 切换测回时触发 - * - * @param cycleIndex - */ - public void switch2Cycle(int cycleIndex) { - //由于井定向的距离测量是不用切换测回的,在一个页面展示了两个测回 -// if (isInValidate()) { -// return; -// } -// _DoCalScheduleInSingleCycleState.enter(this, cycleIndex); - } - - /** - * 进入开始测量的时候触发 - * - * @param cycleIndex - */ - public void calScheduleWhenEnterSurveyFragment(int cycleIndex) { - if (isInValidate()) { - return; - } - _DoCalScheduleInSingleCycleState.enter(this, cycleIndex); - } - - public void moveBack() { - if (isInValidate()) { - return; - } - enter(StateType.doMoveBack); - } - - //检测当前状态是否支持从外界主动改变状态 - //如果是空闲或者是测站通过检测是有效的状态 - private boolean isInValidate() { - return currentStateType != StateType.idle - && StateType.stationCheckedSuccess != currentStateType - && !isRotationReadyState(); - } - - - FragmentManager fragmentManager() { - return this.fragmentManager; - } - - LifecycleOwner lifecycleOwner() { - return this.lifecycleOwner; - } - - final boolean isStationAutoClosed() { - return stationRecord.isAutoClose(); - } - - @WorkerThread - public static StateManagerAloneDistance newInstance( - boolean isSupportAutoMode, - @NonNull SurveyorStationRecord stationRecord, - @NonNull Context context, - @NonNull FragmentManager fragmentManager, - @NonNull LifecycleOwner lifecycleOwner, - @NonNull ToleranceDetailRecord toleranceRecord, - @NonNull ISurveyorData surveyorData, - @NonNull ICycleRecorder cycleRecorder, - @NonNull CachedDataAloneDistance cachedData, - @NonNull MeasureVm measureVm, - IScrollDelegate scrollDelegate, - IUIRunner runner) { - //读取测点record - String stationPointId = null; - if (stationRecord.getItems() != null) { - for (SurveyorPoint stationItem : stationRecord.getItems()) { - if (SurveyorPoint.TYPE_STATION.equals(stationItem.getType())) { - stationPointId = stationItem.getPointId(); - break; - } - } - } - PointRecord stationPointRecord = null; - if (stationPointId != null) { - stationPointRecord = SurveyorDatabaseFactory - .instance - .getPointDataSource() - .findByIdSync(stationPointId); - } - if (stationPointRecord == null) { - return null; - } - boolean supportAuto = Test.DEBUG; - //App.isDebug() - if (isSupportAutoMode && - (VipManager.getInstance().checkReg() || VipManager.getInstance().checkControlProLevel())) { - supportAuto = true; - } - StateManagerAloneDistance manager = new StateManagerAloneDistance(supportAuto, - stationRecord, - stationPointRecord, - toleranceRecord, - context, - surveyorData, - cycleRecorder, - cachedData, - measureVm, - scrollDelegate, - fragmentManager, lifecycleOwner, runner); - return manager; - } - - @Override - public boolean isAutoModeOpen() { - return autoMode == AutoModeType.start; - } - - @Override - public boolean isAutoModeClose() { - return autoMode == AutoModeType.stop; - } - - @Override - public boolean isAutoModeNotSpecial() { - return autoMode == AutoModeType.unknown; - } - - @Override - public void openAutoMode() { - autoMode = AutoModeType.start; - } - - @Override - public void closeAutoMode() { - autoMode = AutoModeType.stop; - } - - @Override - public void resetAutoMode() { - autoMode = AutoModeType.unknown; - } - - @Override - public int isReadyAutoSurvey() { - if (!supportAutoSurvey) { - return ControlSurveyResult.CODE_ERROR; - } - if (!surveyor.isReady()) { - return ControlSurveyResult.CODE_ERROR; - } - if (getRequestSurveyorParamAuto() == null) { - return ControlSurveyResult.CODE_ERROR; - } - - double instrumentHeight = getInsturmentHeight(); - Coordinate stationBasePoint = getStationCoord(); - - return getRequestSurveyorParamAuto().checkAutoCondition(getCachedData(), stationBasePoint, instrumentHeight); - } - - @Override - public String isMeasuredValueMatchDesign() { - if (!supportAutoSurvey) return null; - - double instrumentHeight = getInsturmentHeight(); - Coordinate stationBasePoint = getStationCoord(); - - List originMeasureList = getRequestSurveyorParamAuto().getOriginMeasureList(getCachedData()); - - return AutoSurveyorMethod.checkAutoSurveyorMeasuredValue(stationBasePoint, instrumentHeight, originMeasureList); - } - - @Override - public boolean isSurveying() { - return currentStateType == StateType.doSurveyor || currentStateType == StateType.doAutoSurveyor; - } - - @Override - public boolean isAutoSurveying() { - return isAutoModeOpen(); - } - - public void switchCurrentMeasurePosition(int position) { - if (currentStateType == StateType.idle) { - __BaseState baseState = stateMap.get(currentStateType); - if (baseState != null) { - baseState.setSurveyPosition(position, LeftOrRight.left); - } - } - } - - public CachedDataAloneDistance getCachedData() { - return cachedData; - } - - @NonNull - public ToleranceDetailRecord getToleranceRecord() { - return toleranceRecord; - } - - - private Coordinate getStationCoord() { - if (PointRecord.TYPE_KNOWN_POINT.equals(stationPointRecord.getPointType())) { - return new Coordinate( - stationPointRecord.getX(), - stationPointRecord.getY(), - stationPointRecord.getZ()); - } - return null; - } - - public double getInsturmentHeight() { - return DigitalUtil.valueOfDoubleString(stationRecord.getInstrumentHeight(), 0); - } - - public RequestSurveyorParamAuto getRequestSurveyorParamAuto() { - return measureVm.getRequestSurveyorParamAuto(); - } - - - public void refreshGoBackBtnEnable() { - CachedDataAloneDistance cachedData = getCachedData(); - int currentCycle = cycleRecorder.currentCycleIndex(); - String pointId = getCachedData().pointId(currentCycle, 0); - String cacheKey = IdUtil.createSurveyorRecordId(stationId(), currentCycle, pointId, LeftOrRight.left); - AloneDistanceRecord aloneDistanceRecord = cachedData.getAloneDistanceRecord(cacheKey); - boolean isRollBackBtnEnable = aloneDistanceRecord != null && !aloneDistanceRecord.distanceValues.isEmpty(); - EventBus.getDefault().post(new RefreshGoBackButtonAloneDistance(isRollBackBtnEnable)); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckReadDataState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckReadDataState.java deleted file mode 100644 index 6ab37f0..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckReadDataState.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; - -import net.tatans.tensorflowtts.tts.TtsManager; - -/** - * 检测当前测量数据读数互差 - */ -class _CheckReadDataState extends __BaseState { - private static final int RESULT_SUCCESS = 0; - private static final int RESULT_FAILURE_HOR = 1; - private static final int RESULT_FAILURE_VER = 2; - private static final int RESULT_FAILURE_DISTANCE = 3; - private final IAutoModeSwitcher autoModeSwitcher; - - public _CheckReadDataState(StateManagerAloneDistance stateManager, IAutoModeSwitcher autoModeSwitcher) { - super(StateType.checkReadData, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - //先检测测量值和设计值是否匹配(仅在自动测量打开下检测) - String error = autoModeSwitcher.isMeasuredValueMatchDesign(); - if (error != null) { - failureTipsWithAutoStandStill(error); - return; - } - - onCompleted(RESULT_SUCCESS); - } - - private void onCompleted(int result) { - if (RESULT_SUCCESS == result) { - navigation2(StateType.checkSingleCycle); - } else { - String msg = ""; - switch (result) { - case RESULT_FAILURE_HOR: - msg = Tools.getString(R.string.hor_angle_read_data_limit); - break; - case RESULT_FAILURE_VER: - msg = Tools.getString(R.string.ver_angle_read_data_limit); - break; - case RESULT_FAILURE_DISTANCE: - msg = Tools.getString(R.string.distance_read_data_limit); - break; - default: - navigation2(StateType.idle); - return; - } - if (isAutoSurveyOpen()) { - TtsManager.getInstance().speak(msg); - } - failureTipsWithAutoStandStill(msg); - } - } - - /** - * 斜距两次读数差 - * - * @param distance1 读数1 - * @param distance2 读数2 - * @return 读数差(单位毫米) - */ - public static double distanceReadDiff(double distance1, double distance2) { - return Math.abs(distance1 - distance2) * 1000; - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckSingleCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckSingleCycleState.java deleted file mode 100644 index 6e3d607..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckSingleCycleState.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; - -import java.util.List; - -/** - * 测回内不同方向2c、方向i互差检测 - */ -class _CheckSingleCycleState extends __BaseState { - - public _CheckSingleCycleState(StateManagerAloneDistance stateManager) { - super(StateType.checkSingleCycle, stateManager); - } - - @Override - public void enter(Bundle args) { - doCheck(); - } - - private void doCheck() { - ToleranceDetailRecord toleranceRecord = getToleranceRecord(); - CachedDataAloneDistance cachedData = getCachedData(); - int surveyorCount = getSurveyorCount(); - int cycleIndex = getCycleRecorder().currentCycleIndex(); - int currentIndex = getCurrentIndex(); - double distCyclesDifference = toleranceRecord.getSlopeCycleDistanceDifference()/*slopeCycleDistanceDifference*/; - AloneDistanceRecord aloneDistanceRecord = getAloneDistanceRecord(currentIndex); - if (aloneDistanceRecord == null || aloneDistanceRecord.distanceValues.size() < surveyorCount * 2) { - //进入旋转到位状态等待点击继续测量 - navigation2(StateType.doWellMeasureRotationReady); - return; - } - - List valuesFirst = aloneDistanceRecord.distanceValues.subList(0, surveyorCount); - List valuesSecond = aloneDistanceRecord.distanceValues.subList(surveyorCount, surveyorCount * 2); - - - Double averageFirst = Tools.calculateCollectionDoubleAverage(valuesFirst); - Double averageSecond = Tools.calculateCollectionDoubleAverage(valuesSecond); - - double compareValue = Math.abs(averageFirst - averageSecond); - - if (compareValue * 1000 > distCyclesDifference) { - optionTips(Tools.getString(R.string.cycle_between_distance_limit) + distCyclesDifference, - Tools.getString(R.string.retest_cycle), - Tools.getString(R.string.retest_point), - () -> { - cachedData.deleteAloneDistanceRecord(stationId(), cycleIndex, currentIndex, LeftOrRight.left, true); - //更新进度 - setCurrentCycle(cycleIndex); - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - findTargetFromBeginInCurrentCycle(false); - }, - () -> { - //重测目标 - cachedData.deleteAloneDistanceRecord(stationId(), cycleIndex, currentIndex, LeftOrRight.left, false); - //更新进度 - setCurrentCycle(cycleIndex); - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - findTargetFromBeginInCurrentCycle(false); - }, - () -> { - enterIdleAndClearSurveyStateAndResetAutoMode(true); - }); - - } else { - onSuccess(); - } - } - - private void onSuccess() { - //更新测量进度 - setSingleCycleSchedule(getCycleRecorder().currentCycleIndex(), - SurveyorScheduleConstants.STATUE_VALUE_CHECKED); - //跳转 - navigation2(StateType.isSingleCycleCompleted); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationState.java deleted file mode 100644 index 983335c..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationState.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.SurveyorCycleUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.utils.Util; - -import java.util.ArrayList; -import java.util.List; - -/** - * 执行「测站检测」 - *

- * 前置条件: - * 所有测回都完成测量,并且通过「测回内检测」 - */ -public class _CheckStationState extends __BaseState { - - public _CheckStationState(StateManagerAloneDistance stateManager) { - super(StateType.checkStation, stateManager); - } - - @Override - public void enter(Bundle args) { - //执行测站检测 - String error = _stationCheckAloneDistance(stationId(), getToleranceRecord(), getCachedData()); - if (error == null || error.isEmpty()) { - //进入finish状态 - navigation2(StateType.stationCheckedSuccess); - } else { - failureTipsWithAutoStandStill(error); - } - } - - public static String _stationCheckAloneDistance(final String stationId, - final ToleranceDetailRecord toleranceRecord, - final CachedDataAloneDistance cachedDataSource) { - - final int cycleCount = ToleranceDetailRecord.ALONE_DISTANCE_CYCLE_COUNT; - final int surveyorCount = toleranceRecord.getSurveyorCount(); - - - //测回间斜距互差 - double distCyclesDifference = toleranceRecord.getSlopeCycleDistanceDifference()/*slopeCycleDistanceDifference*/; - List<_ErrorItem> distError = new ArrayList<>(); - - List<_Point> pointArrayList = new ArrayList<>(); - //遍历第一测回,收集所有待测点id - for (int index = 0; index < cachedDataSource.pointCount(); index++) { - pointArrayList.add(new _Point(cachedDataSource.pointId(0, index), cachedDataSource.pointName(0, index))); - } - // if (!distError.isEmpty()) { -// stringBuilder.append("测回间距离较差超限(限差:") -// .append(Util.formatDouble2String(distLimit, 1)) -// .append("'')"); -// for (_ErrorItem item : distError) { -// stringBuilder -// .append("\n ") -// .append(item.pointName) -// .append(":\n") -// .append(" |") -// .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) -// .append("-") -// .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) -// .append("| = ") -// .append(Util.formatDouble2String(item.difference, 1)) -// .append("'')"); -// } -// } - return ""; - } - - /** - * 根据超限信息生成错误描述 - * - * @param horValueError 水平角同方向值互差 - * @param verValueError 垂直角同方向值互差 - */ - private static String _errorString(double horLimit, double verLimit, double verILimit, double distLimit, - List<_ErrorItem> horValueError, List<_ErrorItem> verValueError, List<_ErrorItem> verIError, List<_ErrorItem> distError) { - if (horValueError.isEmpty() && verValueError.isEmpty()) { - return null; - } - StringBuilder stringBuilder = new StringBuilder(); - if (!horValueError.isEmpty()) { - stringBuilder.append(Tools.getString(R.string.cycle_between_same_direction_value_limit)) - .append(Util.formatDouble2String(horLimit, 1)) - .append("'')"); - for (_ErrorItem item : horValueError) { - stringBuilder - .append("\n ") - .append(item.pointName) - .append(":\n") - .append(" |") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) - .append("-") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) - .append("| = ") - .append(Util.formatDouble2String(item.difference, 1)) - .append("'')"); - } - } - - if (!verValueError.isEmpty()) { - stringBuilder.append("\n").append(Tools.getString(R.string.cycle_between_ver_angle_limit)) - .append(Util.formatDouble2String(verLimit, 1)) - .append("'')"); - for (_ErrorItem item : verValueError) { - stringBuilder - .append("\n ") - .append(item.pointName) - .append(":\n") - .append(" |") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) - .append("-") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) - .append("| = ") - .append(Util.formatDouble2String(item.difference, 1)) - .append("'')"); - } - } - - if (!verIError.isEmpty()) { - stringBuilder.append("\n").append(Tools.getString(R.string.ver_angle_i_same_direction_each_cycle)) - .append(Util.formatDouble2String(verILimit, 1)) - .append("'')"); - for (_ErrorItem item : verIError) { - stringBuilder - .append("\n ") - .append(item.pointName) - .append(":\n") - .append(" |") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) - .append("-") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) - .append("| = ") - .append(Util.formatDouble2String(item.difference, 1)) - .append("'')"); - } - } - - if (!distError.isEmpty()) { - stringBuilder.append("\n").append(Tools.getString(R.string.cycle_between_distance_limit_brackets)) - .append(Util.formatDouble2String(distLimit, 1)) - .append("'')"); - for (_ErrorItem item : distError) { - stringBuilder - .append("\n ") - .append(item.pointName) - .append(":\n") - .append(" |") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) - .append("-") - .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) - .append("| = ") - .append(Util.formatDouble2String(item.difference, 1)) - .append("'')"); - } - } - - return stringBuilder.toString(); - } - - /** - * 存储错误信息的item - */ - private static class _ErrorItem { - final String pointName; - final int cycleIndex1; - final int cycleIndex2; - final double difference; - - public _ErrorItem(String pointName, int cycleIndex1, int cycleIndex2, double difference) { - this.pointName = pointName; - this.cycleIndex1 = cycleIndex1; - this.cycleIndex2 = cycleIndex2; - this.difference = difference; - } - } - - private static class _Point { - final String pointId; - final String pointName; - - _Point(String pointId, String pointName) { - this.pointId = pointId; - this.pointName = pointName; - } - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationSuccessState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationSuccessState.java deleted file mode 100644 index f120c55..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_CheckStationSuccessState.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; - -import net.tatans.tensorflowtts.tts.TtsManager; - -import com.bingce.controlnetwork.R; - -class _CheckStationSuccessState extends __BaseState { - - public _CheckStationSuccessState(StateManagerAloneDistance stateManager) { - super(StateType.stationCheckedSuccess, stateManager); - } - - @Override - public void enter(Bundle args) { - ISurveyorData surveyorData = getSurveyorData(); - surveyorData.clearSurveyStateAndPosition(); - //设置测量进度(数据库存储) - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_CHECKED); - //通知刷新 - tips(getContext().getString(R.string.tips_all_cycle_has_finish_and_checked), null); - if (isAutoSurveyOpen()) { - runOnUI(() -> TtsManager.getInstance().speak(getContext().getString(R.string.tips_all_cycle_has_finish_and_checked))); - } - //清除测量状态,进入idle,停止自动测量 - enterIdleAndClearSurveyStateAndResetAutoMode(true); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoAutoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoAutoSurveyorState.java deleted file mode 100644 index 2ca12da..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoAutoSurveyorState.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.totalstation.ControlSurveyResult; - -import net.tatans.tensorflowtts.tts.TtsManager; - -/** - * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 - */ -class _DoAutoSurveyorState extends __BaseState { - private final IAutoModeSwitcher autoModeSwitcher; - - public _DoAutoSurveyorState(StateManagerAloneDistance stateManager, IAutoModeSwitcher autoModeSwitcher) { - super(StateType.doAutoSurveyor, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - if (autoModeSwitcher.isReadyAutoSurvey() == ControlSurveyResult.CODE_SUCCESS) { - autoModeSwitcher.openAutoMode(); - navigation2(StateType.doMove2NextValidate); - TtsManager.getInstance().speak(Tools.getString(R.string.start_auto_measure)); - } - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalAdjustState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalAdjustState.java deleted file mode 100644 index e62f793..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalAdjustState.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.content.Context; -import android.os.Bundle; - -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.method.SurveyorAdjustMethod; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; -import com.bingce.controlnetwork.fragment.TipsFragment; -import com.bingce.utils.ThreadPoolUtil; - -import java.util.ArrayList; - -/** - * 平差计算 - */ -public class _DoCalAdjustState extends __BaseState { - - public _DoCalAdjustState(StateManagerAloneDistance stateManager) { - super(StateType.doCalAdjust, stateManager); - } - - @Override - public void enter(Bundle args) { - - } - - public static void doCalAdjust(String stationId, CachedDataAloneDistance cachedData, Context context, FragmentManager fragmentManager - , LifecycleOwner lifecycleOwner) { - ThreadPoolUtil.execute(() -> { - SurveyorAdjustMethod.calAloneDistance( - stationId, cachedData, new SurveyorAdjustMethod.ICallback() { - @Override - public void onGet(ArrayList finalItemList, Boolean isShowSlopDistance) { -// //清除测量状态,进入idle,停止自动测量 -// enterIdleAndClearSurveyStateAndResetAutoMode(true); - //展示结果数据 - //检测归零值是否为负,如果是需要+2PI - for (SurveyorAdjustMethod.Item item : finalItemList) { - if (item.getHorAngle() < 0) { - item.setHorAngle(Math.PI * 2 + item.getHorAngle()); - } - } - StationDataAdjustDialogFragment.showDialog(StationDataAdjustDialogFragment.TYPE_ALONE_DISTANCE, finalItemList, isShowSlopDistance, fragmentManager); - } - - @Override - public void onFailure(String error) { - ThreadPoolUtil.executeInMain(() -> { - TipsFragment.tipsOnly(fragmentManager, lifecycleOwner, context, error); - }); - } - }); - - //伴随平差 设置进度为通过检测 - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getAllCycleScheduleKey(stationId, SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE), - SurveyorScheduleConstants.STATUE_VALUE_CHECKED)); - - }); - - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalScheduleInSingleCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalScheduleInSingleCycleState.java deleted file mode 100644 index ff1e497..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoCalScheduleInSingleCycleState.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.event.SurveyStateEvent; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment; - -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment; - -/** - * 在单个测回内计算当前测量进度。 - *

- * 1.如果有没有完成测量,则跳转到相应位置。 - * 2.如果测量完成,检测数据限差 - * 3.进入idle - */ -class _DoCalScheduleInSingleCycleState extends __BaseState { - private final IAutoModeSwitcher autoModeSwitcher; - - public _DoCalScheduleInSingleCycleState(StateManagerAloneDistance stateManager, IAutoModeSwitcher autoModeSwitcher) { - super(StateType.doCalScheduleSingleCycle, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - final public void enter(Bundle args) { - - int pointCount = getCachedData().pointCount(); - if (pointCount == 0) { - postBtnEvent(); - return; - } - - //重置自动测量状态 - if (autoModeSwitcher.isAutoModeClose()) { - autoModeSwitcher.resetAutoMode(); - } - //计算状态之前,重置测量状态 - getSurveyorData().clearSurveyStateAndPosition(); - - ICycleRecorder cycleRecorder = getCycleRecorder(); - cycleRecorder.changeCycleIndex(args.getInt(KEY_CYCLE_INDEX, 0)); - setCurrentCycle(cycleRecorder.currentCycleIndex()); - - //1.检测当前cycle是否完成测量 - boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( - stationId(), - getCycleRecorder().currentCycleIndex(), - getCachedData(), getSurveyorCount()); - //2.如果当前测回还有待测数据,则执行测量 - if (!completed) { - //从当前测回开始处查找目标并执行测量 - findTargetFromBeginInCurrentCycle(false); - return; - } - //3.如果当前测回结束测量,判断是否通过检测 -// ToleranceDetailRecord toleranceDetailRecord = getToleranceRecord(); -// double horCycle2CDiff = toleranceDetailRecord.getHorCycleDirect2CDifference(); -// double verCycle2CDiff = toleranceDetailRecord.getVerCycleDirectIDifference(); -// String error = SingleCycleCheckMethod.check( -// horCycle2CDiff, -// verCycle2CDiff, -// stationId(), -// getCycleRecorder().currentCycleIndex(), -// getSurveyorData(), -// getCachedData()); -// if (error != null && !error.isEmpty()) { -// SingleCycleTipsMethod.showTips(error, -// stationId(), -// getCycleRecorder().currentCycleIndex(), -// stateDelegate(), -// fragmentManager(), -// lifecycleOwner()); -// return; -// } - //4.更新测站状态,在当前测回经过检测 - setSingleCycleSchedule(getCycleRecorder().currentCycleIndex(), - SurveyorScheduleConstants.STATUE_VALUE_CHECKED); - - //6.清空测量状态 - onCompletedCheck(); - } - - protected void onCompletedCheck() { - enterIdleAndClearSurveyStateAndResetAutoMode(true); - } - - protected static final String KEY_CYCLE_INDEX = "___cycle__index__"; - - static void enter(StateManagerAloneDistance stateManager, int cycleIndex) { - Bundle args = new Bundle(); - args.putInt(KEY_CYCLE_INDEX, cycleIndex); - stateManager.enter(StateType.doCalScheduleSingleCycle, args); - } - - private void postBtnEvent() { - int pointCount = getCachedData().pointCount(); - if (pointCount == 0) { - SurveyStateEvent.postCompleted(MeasureFragment.POSITION_DISTANCE_MEASURE); - } else { - SurveyStateEvent.postIdle(MeasureFragment.POSITION_DISTANCE_MEASURE); - } - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteAllCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteAllCycleState.java deleted file mode 100644 index 1e49e92..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteAllCycleState.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.config.ConfigConstants; -import com.bingce.controlapphelper.datasource.database.config.IConfigDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.utils.ThreadPoolUtil; - -import com.bingce.controlnetwork.R; - -/** - * 删除本测站所有测回数据 - * 对于钢丝测距 所有两测回数据都在一个view里显示了,不用切换 - */ -class _DoDeleteAllCycleState extends __BaseState { - - private static final String KEY_STATION_ID = "__station_id"; - - static Bundle args(String stationId) { - Bundle args = new Bundle(); - args.putString(KEY_STATION_ID, stationId); - return args; - } - - public _DoDeleteAllCycleState(StateManagerAloneDistance stateManager) { - super(StateType.doDeleteAllCycle, stateManager); - } - - @Override - public void enter(Bundle args) { - String stationId = args.getString(KEY_STATION_ID); - - optionTipsWithStandStill(getContext().getString(R.string.tips_delete_station_all_surveyor_records), - () -> deleteAllCycleData(stationId)); - } - - private void deleteAllCycleData(String stationId) { - ThreadPoolUtil.execute(() -> { - //删除数据 - getCachedData().deleteAloneDistanceRecord(stationId); - - //清除已经提示测站可以检测标识 - IConfigDataSource configDataSource = - SurveyorDatabaseFactory.instance.getConfigDataSource(); - String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId; - configDataSource.setSync(key, ConfigConstants.VALUE_NO); - - //重置所有测回进度 - setAllCycleScheduleSync(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setSingleCycleScheduleSync(cycleIndexDefault, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - - //从第一测回开始 - setCurrentCycle(cycleIndexDefault); - //重新测量,并刷新 - findTargetFromBeginInCurrentCycle(true); - }); - } - - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteCurrentCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteCurrentCycleState.java deleted file mode 100644 index 0c07e34..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoDeleteCurrentCycleState.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.config.ConfigConstants; -import com.bingce.controlapphelper.datasource.database.config.IConfigDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.state.StateType; - -import com.bingce.controlnetwork.R; - -class _DoDeleteCurrentCycleState extends __BaseState { - public _DoDeleteCurrentCycleState(StateManagerAloneDistance stateManager) { - super(StateType.doDeleteCurrentCycle, stateManager); - } - - @Override - public void enter(Bundle args) { - String stationId = args.getString(KEY_STATION_ID); - int cycleIndex = args.getInt(KEY_PERIOD_INDEX); - - optionTipsWithStandStill(getContext().getString(R.string.tips_delete_current_cycle_surveyor_record), - () -> { - //删除数据 - getCachedData().deleteAloneDistanceRecord(stationId, cycleIndex); - - //清除已经提示测站可以检测标识 - IConfigDataSource configDataSource = - SurveyorDatabaseFactory.instance.getConfigDataSource(); - String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId; - configDataSource.set(key, ConfigConstants.VALUE_NO); - - //重置进度 - //当前测回 - setCurrentCycle(cycleIndex); - //所有测回未完成 - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - //单个测回未完成 - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - //重新测量,并刷新 - findTargetFromBeginInCurrentCycle(true); - }); - } - - private static final String KEY_STATION_ID = "__station_id"; - private static final String KEY_PERIOD_INDEX = "__period_index__"; - - static Bundle args(String stationId, int periodIndex) { - Bundle args = new Bundle(); - args.putString(KEY_STATION_ID, stationId); - args.putInt(KEY_PERIOD_INDEX, periodIndex); - return args; - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMove2NextValidateState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMove2NextValidateState.java deleted file mode 100644 index c0cff3c..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMove2NextValidateState.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.FindTargetMethod; -import com.bingce.controlapphelper.surveyor.state.StateType; - -/** - * 移动到一个待测量位置 - *

- * 不会跳转到其他测期 - *

- * 可能涉及转向(盘左->盘右) - */ -class _DoMove2NextValidateState extends __BaseState { - - public _DoMove2NextValidateState(StateManagerAloneDistance stateManager) { - super(StateType.doMove2NextValidate, stateManager); - } - - @Override - public void enter(Bundle args) { - CachedDataAloneDistance cachedData = getCachedData(); - ISurveyorData surveyorData = getSurveyorData(); - ICycleRecorder cycleRecorder = getCycleRecorder(); - - int pointCount = cachedData.pointCount(); - int currentIndex = surveyorData.currentIndex(); - if (currentIndex < 0) { - currentIndex = 0; - } - final int currentCycleIndex = cycleRecorder.currentCycleIndex(); - final LeftOrRight currentSurveyorState = surveyorData.leftOrRight(); - - - FindTargetMethod.Target needMeasureForAloneDistanceTarget = FindTargetMethod.findNeedMeasureTargetInSingleCycleForAloneDistance(stationId(), currentCycleIndex, - currentIndex, - currentSurveyorState, - pointCount, - true, - cachedData); - - if (needMeasureForAloneDistanceTarget != null) { - navigation2(needMeasureForAloneDistanceTarget.itemIndex, needMeasureForAloneDistanceTarget.leftOrRight); - return; - } - - - //3.当前测回完成测量,停留状态 - //重置标识 - enterIdleAndClearSurveyorStatePosition(); - } - - /** - * 跳转到下一目标点 - * - * @param targetIndex 目标点索引 - * @param targetSurveyorState 测量状态(盘左or盘右) - */ - private void navigation2(int targetIndex, LeftOrRight targetSurveyorState) { - //更新测量进度 - setSurveyPosition(targetIndex, targetSurveyorState); - //清除测量状态,进入idle,但是不停止自动测量 - enterIdleAndClearSurveyStateAndResetAutoMode(false); - //滚动 - scroll2(targetIndex); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMoveBackState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMoveBackState.java deleted file mode 100644 index 0f87315..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoMoveBackState.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; - -import blankj.utilcode.util.ToastUtils; - -/** - * 移动到上一测量结点,伴随删除上次测量数据 - */ -public class _DoMoveBackState extends __BaseState { - - public _DoMoveBackState(StateManagerAloneDistance stateManager) { - super(StateType.doMoveBack, stateManager); - } - - @Override - public void enter(Bundle args) { - CachedDataAloneDistance cachedDataSource = getCachedData(); - ISurveyorData surveyorDataSource = getSurveyorData(); - ICycleRecorder cycleRecorder = getCycleRecorder(); - - final int pointCount = cachedDataSource.pointCount(); - final int currentCycle = cycleRecorder.currentCycleIndex(); - final int currentIndex = surveyorDataSource.currentIndex(); - final LeftOrRight leftOrRight = surveyorDataSource.leftOrRight(); - - int targetIndex = currentIndex; - if (targetIndex < 0) { - //如果测量结束,直接使用0号点盘右 - targetIndex = pointCount - 1; - } - warningWithStandStill(cachedDataSource, currentCycle, targetIndex, LeftOrRight.left); - } - - private void warningWithStandStill( - CachedDataAloneDistance cachedDataSource, - int currentCycle, int itemIndex, LeftOrRight leftOrRight) { - optionTipsWithStandStill(Tools.getString(R.string.roll_back_node_data), - () -> { - //删除当前数据 - int nextSurveyorPointIndex = cachedDataSource.deleteAloneDistanceRecord(stationId(), - currentCycle, itemIndex, leftOrRight, true); - - if (nextSurveyorPointIndex == -1) { - ToastUtils.showShort(R.string.roll_back_failed); - navigation2(StateType.idle); - return; - } - - AloneDistanceRecord aloneDistanceRecord = getAloneDistanceRecord(nextSurveyorPointIndex); - if (aloneDistanceRecord != null && aloneDistanceRecord.distanceValues.size() == getSurveyorCount()) { - navigation2(StateType.doWellMeasureRotationReady); - } else { - navigation2(StateType.idle); - } - - //重置进度 - setCurrentCycle(nextSurveyorPointIndex); - setSingleCycleSchedule(currentCycle, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - - resetSchedule(this, nextSurveyorPointIndex, leftOrRight); - }); - } - - private void resetSchedule(__BaseState state, - int targetIndex, - LeftOrRight leftOrRight) { - //设置测量目标点 - state.setSurveyPosition(targetIndex, leftOrRight); - - state.scroll2(targetIndex); - } - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoSurveyorState.java deleted file mode 100644 index d02be7c..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoSurveyorState.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; - -import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; -import com.bingce.controlapphelper.event.SurveyStateEvent; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorListener; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorRemindListener; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParam; -import com.bingce.controlapphelper.util.DebugMsgUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.surveyor.state.StateConstants; -import com.bingce.device.Device; -import com.bingce.totalstation.TotalStation; -import com.bingce.totalstation.protocol.south.SouthAndroidBtInterface; -import com.bingce.totalstation.protocol.topcon.TopconInterface; - -import net.tatans.tensorflowtts.tts.TtsManager; - -import blankj.utilcode.util.ToastUtils; -import blankj.utilcode.util.Utils; - -/** - * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 - */ -class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurveyorRemindListener { - private final ISurveyState surveyState; - //最多测量次数,如果5次测量都没有获取正常数据,则跳过 - private static final int MAX_SURVEYOR_COUNT = 3; - private static int failureCount = 0; - private static final int RESULT_SUCCESS = 0; - private static final int RESULT_FAILURE_EXCEED_MAX = 1;//测量失败次数超出最大限制 - private static final int RESULT_FAILURE_ERROR = 2;//测量失败,又没有允许重复尝试 - private static final boolean allowTryWhenFailure = true;//在测量失败的时候,是否允许重新测量 - - private int measureTimeIndex = 0; - private boolean isAlreadyRemindUserAimingAtWire = false; - - private final Handler handler; - - public _DoSurveyorState(StateManagerAloneDistance stateManager, ISurveyState surveyState) { - super(StateType.doSurveyor, stateManager); - this.surveyState = surveyState; - handler = new Handler(Looper.getMainLooper()); - } - - @Override - public void enter(Bundle args) { - measureTimeIndex = 0; - - isAlreadyRemindUserAimingAtWire = false; - if (args != null) { - isAlreadyRemindUserAimingAtWire = args.getBoolean(StateConstants.KEY_IS_ROTATION_READY_STATE); - } - - //3.其他测回没有正在测量数据,则在当前测回执行测量 - doSurveyor(); - } - - private void doSurveyor() { - failureCount = 0; - //判断设备是否连接 - if (surveyorImpl().isReady()) { - //发送测量信号 - SurveyStateEvent.postSurveying(positionFragment); - //注册接收测量数据 - surveyorImpl().prepareSurveyor(); - sendSurveyRequest(); - } else { - enterIdleAndClearSurveyStateAndResetAutoMode(true); - Device.getInstance().remindConnectDevice(); - } - } - - @Override - public void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { - //重置错误读数 - failureCount = 0; - AloneDistanceRecord aloneDistanceRecord - = getCachedData().cacheAloneDistance(stationId(), StateManagerAloneDistance.CYCLE_INDEX_DEFAULT, getCurrentIndex(), sd, hd); - - //刷新页面 - refreshUI(); - int surveyorCount = getCachedData().getSurveyorCount(); - if (aloneDistanceRecord.distanceValues.size() == surveyorCount) { - ToastUtils.showShort(Utils.getApp().getString(R.string.alone_distance_first_round_measure_finish)); - onSuccess(); - } else if (aloneDistanceRecord.distanceValues.size() >= surveyorCount * 2) { - onSuccess(); - } else { - //当数据不够的时候 继续发送指令 - measureTimeIndex++; - if (TotalStation.getInstance() instanceof TopconInterface) { - //这个仪器需要延迟500毫秒发送指令 - handler.postDelayed(this::sendSurveyRequest, 500); - } else if (TotalStation.getInstance() instanceof SouthAndroidBtInterface) { - handler.postDelayed(this::sendSurveyRequest, 100); - } else { - sendSurveyRequest(); - } - } - } - - @Override - public void onError(String errorMsg) { - TtsManager.getInstance().speak(errorMsg); - if (allowTryWhenFailure) {//允许重新测量 - //测量出现异常,需要处理 - failureCount++; - if (failureCount >= MAX_SURVEYOR_COUNT) { - if (isAutoSurveyOpen()) { - TtsManager.getInstance().speak(Tools.getString(R.string.many_measure_failed)); - } - onCompleted(RESULT_FAILURE_EXCEED_MAX, Tools.getString(R.string.many_measure_failed_1)); - } else { - //再次尝试 - DebugMsgUtil.canWrite("仪器返回错误信息:" + errorMsg); - DebugMsgUtil.canWrite("开始再次测量"); - - sendSurveyRequest(); - ToastUtils.showShort(R.string.receive_data_time_out); - } - } else { - onCompleted(RESULT_FAILURE_ERROR, errorMsg); - } - } - - private void sendSurveyRequest() { - SurveyorPoint surveyorPoint = getCachedData().getSurveyorPoint(getCycleRecorder().currentCycleIndex(), getCurrentIndex()); - - ISurveyorData surveyorData = getSurveyorData(); - int measureTimeIndex = 0; - surveyorImpl().requestSurveyor(new RequestSurveyorParam(getRequestSurveyorParamAuto(), getInsturmentHeight(), surveyorPoint, measureTimeIndex, - surveyorData.currentIndex(), surveyorData.leftOrRight(), isAlreadyRemindUserAimingAtWire)); - } - - private void onSuccess() { - onCompleted(RESULT_SUCCESS, ""); - } - - private void onCompleted(int result, String msg) { - //退出测量 - surveyorImpl().exitSurveyor(); - switch (result) { - case RESULT_SUCCESS://进入读数检测状态 - //检测是否处于「自动测量」 - if (!surveyState.isAutoSurveying()) { - SurveyStateEvent.postSuccess(positionFragment); - } - navigation2(StateType.checkReadData); - break; - case RESULT_FAILURE_EXCEED_MAX: - case RESULT_FAILURE_ERROR: { - SurveyStateEvent.postFailure(positionFragment); - //进入失败状态 - Bundle args = _SurveyorFailureState.args(msg); - navigation2(StateType.SurveyorFailure, args); - } - break; - default: - throw new RuntimeException("un reached state -- surveyor"); - } - } - - @Override - public void remindUserAimingAtWire() { - //退出测量 - surveyorImpl().exitSurveyor(); - - Bundle bundle = new Bundle(); - bundle.putString(StateConstants.KEY_ROTATION_STATE_FROM_WHERE, StateConstants.ROTATION_STATE_FROM_WHERE_MEASURE); - navigation2(StateType.doWellMeasureRotationReady, bundle); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoWellMeasureRotationReadyState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoWellMeasureRotationReadyState.java deleted file mode 100644 index be6c86a..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_DoWellMeasureRotationReadyState.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; -import android.text.TextUtils; - -import com.bingce.controlapphelper.event.AutoSurveyorButtonVisibleEvent; -import com.bingce.controlapphelper.event.SurveyStateEvent; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.surveyor.state.StateConstants; - -import net.tatans.tensorflowtts.tts.TtsManager; - -import org.greenrobot.eventbus.EventBus; - -import com.bingce.controlnetwork.surveyor.state.StateConstants; - -/** - * 钢丝测量旋转到位状态 - */ -class _DoWellMeasureRotationReadyState extends __BaseState { - - public _DoWellMeasureRotationReadyState(StateManagerAloneDistance stateManager) { - super(StateType.doWellMeasureRotationReady, stateManager); - } - - @Override - public void enter(Bundle args) { - if (args != null) { - String fromWhere = args.getString(StateConstants.KEY_ROTATION_STATE_FROM_WHERE); - if (TextUtils.equals(fromWhere, StateConstants.ROTATION_STATE_FROM_WHERE_MEASURE)) { - runOnUI(() -> TtsManager.getInstance().speak(getContext().getString(R.string.please_aiming_at_alone_distance_point_then_measure))); - } - } - //更新回退按钮状态 - refreshGoBack(); - SurveyStateEvent.postIdle(positionFragment); - EventBus.getDefault().post(new AutoSurveyorButtonVisibleEvent(positionFragment, false, true)); - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IdleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IdleState.java deleted file mode 100644 index 4fa88a0..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IdleState.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import androidx.annotation.NonNull; - -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.AutoSurveyorButtonVisibleEvent; -import com.bingce.controlapphelper.event.SurveyStateEvent; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.totalstation.ControlSurveyResult; -import com.bingce.utils.ThreadPoolUtil; - -import org.greenrobot.eventbus.EventBus; - -/** - * 空闲状态 - *

- * 将刷新界面 - */ -class _IdleState extends __BaseState { - private final @NonNull - IAutoModeSwitcher autoModeSwitcher; - - public _IdleState(StateManagerAloneDistance stateManager, @NonNull IAutoModeSwitcher autoModeSwitcher) { - super(StateType.idle, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - - refreshGoBack(); - - ThreadPoolUtil.execute(() -> { - boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( - stationId(), - StateManagerAloneDistance.CYCLE_INDEX_DEFAULT, - getCachedData(), ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT); - - //判断当前条件是否满足自动测量 - boolean haveAutoCondition = autoModeSwitcher.isReadyAutoSurvey() == ControlSurveyResult.CODE_SUCCESS; - - //自动测量是否显示 - EventBus.getDefault().post(new AutoSurveyorButtonVisibleEvent(positionFragment, haveAutoCondition, autoModeSwitcher.isAutoModeOpen())); - - if (haveAutoCondition && autoModeSwitcher.isAutoModeOpen()) { - //继续自动测量 - navigation2(StateType.doSurveyor); - } else { - if (autoModeSwitcher.isAutoModeOpen()) { - autoModeSwitcher.resetAutoMode(); - } - if (completed) { - SurveyStateEvent.postCompleted(positionFragment); - } else { - SurveyStateEvent.postIdle(positionFragment); - } - } - }); - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsAllCycleCompletedState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsAllCycleCompletedState.java deleted file mode 100644 index 701fae1..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsAllCycleCompletedState.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import androidx.annotation.NonNull; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.config.ConfigConstants; -import com.bingce.controlapphelper.datasource.database.config.ConfigRecord; -import com.bingce.controlapphelper.datasource.database.config.IConfigDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.utils.ThreadPoolUtil; - -import net.tatans.tensorflowtts.tts.TtsManager; - -/* - * 检测是否所有 测期都完成了测量 - * - * 只有在当前测期完成测量之后,才会进入当前状态 - * */ -public class _IsAllCycleCompletedState extends __BaseState { - private final IAutoModeSwitcher autoModeSwitcher; - - public _IsAllCycleCompletedState(@NonNull StateManagerAloneDistance stateManager, IAutoModeSwitcher autoModeSwitcher) { - super(StateType.isAllCycleCompleted, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - if (isAutoSurveyOpen()) { - //检测是否已经提示 - //检测是否需要提示测站检测 - IConfigDataSource configDataSource = - SurveyorDatabaseFactory.instance.getConfigDataSource(); - ThreadPoolUtil.execute(() -> { - String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId(); - ConfigRecord record = configDataSource.getByKeySync(key); - if (record == null || ConfigConstants.VALUE_NO.equals(record.getConfigValue())) { - runOnUI(() -> TtsManager.getInstance().speak(Tools.getString(R.string.all_cycle_completed))); - } - }); - } - //标识测站完成测量(数据库存储) - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); - //进入idle状态 - //清除测量状态,进入测站检测,停止自动测量 - enterStationCheckAndClearSurveyStateAndResetAutoMode(); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsSingleCycleCompletedState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsSingleCycleCompletedState.java deleted file mode 100644 index ca23390..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_IsSingleCycleCompletedState.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.IdUtil; - -public class _IsSingleCycleCompletedState extends __BaseState { - private static final int RESULT_YES = 0;//测回结束 - private static final int RESULT_NO = 1;//测回未结束 - - public _IsSingleCycleCompletedState(StateManagerAloneDistance stateManager) { - super(StateType.isSingleCycleCompleted, stateManager); - } - - @Override - public void enter(Bundle args) { - onCompleted( - isSingleCycleCompleted(stationId(), - getCycleRecorder().currentCycleIndex(), - getCachedData(), getSurveyorCount())); - } - - private void onCompleted(boolean completed) { - if (completed) { - //这里先刷新下UI,不然弹窗后面的list不显示最后一条数据 - getSurveyorData().clearSurveyStateAndPosition(); - refreshUI(); - - int cycleIndex = getCycleRecorder().currentCycleIndex(); - //更新单测回测量进度 - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_COMPLETED); - //状态切换 - navigation2(StateType.isAllCycleCompleted); - } else { - findTargetFromBeginInCurrentCycle(false); - } - } - - /** - * 判断单个测回是否测量完成(不要求通过检测) - */ - public static boolean isSingleCycleCompleted(String stationId, int cycleIndex, CachedDataAloneDistance cachedData, int surveyCount) { - int result = RESULT_YES; - for (int index = 0; index < cachedData.pointCount(); index++) { - String pointId = cachedData.pointId(cycleIndex, index); - String leftOrRightKey = IdUtil.createSurveyorRecordId(stationId, cycleIndex, pointId, LeftOrRight.left); - AloneDistanceRecord aloneDistanceRecord = cachedData.getAloneDistanceRecord(leftOrRightKey); - if (aloneDistanceRecord == null || aloneDistanceRecord.distanceValues == null || - aloneDistanceRecord.distanceValues.size() < surveyCount * 2) { - result = RESULT_NO; - break; - } - } - return RESULT_YES == result; - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_SurveyorFailureState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_SurveyorFailureState.java deleted file mode 100644 index 0d532bb..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/_SurveyorFailureState.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; - -/* - * 仪器导致的测量失败 - * - * 全站仪多次测量失败,进入该状态 - * */ -class _SurveyorFailureState extends __BaseState { - - public _SurveyorFailureState(StateManagerAloneDistance stateManager) { - super(StateType.SurveyorFailure, stateManager); - } - - @Override - public void enter(Bundle args) { - String error = ""; - if (args != null) { - error = args.getString(KEY); - } - failureTipsWithAutoStandStill(error + Tools.getString(R.string.please_observe_target)); - } - - private static final String KEY = "error"; - - public static Bundle args(String error) { - Bundle args = new Bundle(); - args.putString(KEY, error); - return args; - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/__BaseState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/__BaseState.java deleted file mode 100644 index 2c94cf3..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/alonedistance/__BaseState.java +++ /dev/null @@ -1,395 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.alonedistance; - -import android.content.Context; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyor; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParamAuto; -import com.bingce.controlapphelper.util.IdUtil; -import com.bingce.controlnetwork.fragment.TipsFragment; -import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment; - -import blankj.utilcode.util.ToastUtils; - -import com.bingce.controlnetwork.fragment.TipsFragment; -import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment; - -abstract class __BaseState { - private final StateType type; - private final StateManagerAloneDistance stateManager; - - protected final int positionFragment = MeasureFragment.POSITION_DISTANCE_MEASURE; - - /** - * 判断常量 - */ - private final int DEFAULT_AUTO_MODE = 0; - private final int RESET_AUTO_MODE = 1; - private final int CLOSE_AUTO_MODE = 2; - - protected final int cycleIndexDefault = StateManagerAloneDistance.CYCLE_INDEX_DEFAULT; - - public __BaseState(final StateType stateType, final StateManagerAloneDistance stateManager) { - this.type = stateType; - this.stateManager = stateManager; - } - - final protected StateType getType() { - return type; - } - - final protected @NonNull - ToleranceDetailRecord getToleranceRecord() { - return stateManager.toleranceRecord; - } - - final protected @NonNull - ISurveyorData getSurveyorData() { - return stateManager.surveyorData; - } - - private @NonNull - IAutoModeSwitcher autoModeRecorder() { - return stateManager; - } - - /** - * 设置测量位置 - */ - final protected void setSurveyPosition(int index, LeftOrRight leftOrRight) { - stateManager.surveyorData.setCurrentIndex(index); - stateManager.surveyorData.setLeftOrRight(leftOrRight); - } - - protected int getCurrentIndex() { - return stateManager.surveyorData.currentIndex(); - } - - protected AloneDistanceRecord getAloneDistanceRecord(int surveyorPointIndex) { - int cycleIndex = getCycleRecorder().currentCycleIndex(); - String pointId = getCachedData().pointId(cycleIndex, surveyorPointIndex); - String cacheKey = IdUtil.createSurveyorRecordId(stationId(), cycleIndex, pointId, LeftOrRight.left); - return getCachedData().getAloneDistanceRecord(cacheKey); - } - - final protected ISurveyor surveyorImpl() { - return stateManager.surveyor; - } - - - @NonNull - final protected CachedDataAloneDistance getCachedData() { - return stateManager.cachedData; - } - - @NonNull - final protected ICycleRecorder getCycleRecorder() { - return stateManager.cycleRecorder; - } - - @NonNull - final protected Context getContext() { - return stateManager.context; - } - - final protected void scroll2(int itemIndex) { - stateManager.scrollDelegate.onScrollTo(itemIndex); - } - - - final protected void toast(String warning) { - ToastUtils.showShort(warning); - } - - final protected void toast(@StringRes int warning) { - ToastUtils.showShort(warning); - } - - public abstract void enter(Bundle args);//进入状态 - - final protected void navigation2(StateType stateType) { - stateManager.enter(stateType); - } - - final protected void navigation2(StateType stateType, Bundle args) { - stateManager.enter(stateType, args); - } - - final protected String stationId() { - return stateManager.stationId(); - } - - protected int getSurveyorCount() { - return stateManager.surveyorData.surveyorCount(); - } - - final protected FragmentManager fragmentManager() { - return stateManager.fragmentManager(); - } - - final protected LifecycleOwner lifecycleOwner() { - return stateManager.lifecycleOwner(); - } - - final protected void tips(String msg, Runnable runnable) { - TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), - getContext(), - msg, - -1, - () -> { - if (runnable != null) { - runnable.run(); - } - }); - } - - /** - * 错误提示 - *

- * 用户不能忽略,点击确定后自动「停留原地」 - */ - final protected void failureTipsWithAutoStandStill(String msg) { - TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), - getContext(), - msg, - -1, - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); - } - - final protected void failureTipsWithAutoStandStill(String msg, Runnable runnable) { - TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), - getContext(), - msg, - -1, - () -> { - runnable.run(); - enterIdleAndClearSurveyStateAndResetAutoMode(true); - }); - } - - final protected void optionTipsWithStandStill(String msg, Runnable confirmCallback) { - optionTips(msg, null, null, - confirmCallback, - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); - } - - final protected void optionTips(String msg, - String confirmButton, - String cancelButton, - Runnable confirmCallback, - Runnable cancelCallback, - Runnable ignoreCallback) { - TipsWith2OptionFragment.tips( - stateManager.fragmentManager(), - stateManager.lifecycleOwner(), - confirmButton, - cancelButton, - null, - msg, - new TipsWith2OptionFragment.IOperatorCallback() { - @Override - public void onConfirm() { - if (confirmCallback == null) { - return; - } - confirmCallback.run(); - } - - @Override - public void onCancel() { - if (cancelCallback == null) { - return; - } - cancelCallback.run(); - } - - @Override - public void onIgnore() { - if (ignoreCallback == null) { - return; - } - ignoreCallback.run(); - } - - @Override - public void onOption() { - } - }); - } - - final protected void runOnUI(Runnable runnable) { - stateManager.runOnUI(runnable); - } - - final protected void setCurrentCycle(int cycle) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getCurrentCycleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE), - String.valueOf(cycle))); - } - - final protected void setCurrentCycleSync(int cycle) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .recordSync( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getCurrentCycleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE), - String.valueOf(cycle))); - } - - final protected void setSingleCycleSchedule(int cycleIndex, String statue) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getSingleCycleScheduleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE, cycleIndex), - statue)); - } - - final protected void setSingleCycleScheduleSync(int cycleIndex, String statue) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .recordSync( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getSingleCycleScheduleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE, cycleIndex), - statue)); - } - - final protected void setAllCycleSchedule(String statue) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE), - statue)); - } - - final protected void setAllCycleScheduleSync(String statue) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .recordSync( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), SurveyorScheduleConstants.SCHEDULE_OR_CYCLE_TYPE_ALONE_DISTANCE), - statue)); - } - - /** - * 如果resetAutoSurveyState为true,将重置autoSurvey状态为unknown - */ - final protected void findTargetFromBeginInCurrentCycle(boolean resetAutoSurveyState) { - getSurveyorData().clearSurveyStateAndPosition(); - if (resetAutoSurveyState) { - autoModeRecorder().resetAutoMode(); - } - navigation2(StateType.doMove2NextValidate); - } - - final protected void enterIdleAndClearSurveyState() { - clearSurveyStateAndCloseAutoModeAndStandStill(DEFAULT_AUTO_MODE, - false, StateType.idle); - } - - final protected void enterIdleAndClearSurveyorStatePosition() { - clearSurveyStateAndCloseAutoModeAndStandStill(DEFAULT_AUTO_MODE, - true, StateType.idle); - } - - /** - * 取消测量,会停在当前位置(索引+盘左or盘右),并进入idle - */ - final protected void enterIdleAndClearSurveyStateAndResetAutoMode(boolean resetAutoMode) { - clearSurveyStateAndCloseAutoModeAndStandStill(resetAutoMode ? RESET_AUTO_MODE : DEFAULT_AUTO_MODE, - false, StateType.idle); - } - - - final protected void enterStationCheckAndClearSurveyStateAndResetAutoMode() { - clearSurveyStateAndCloseAutoModeAndStandStill(RESET_AUTO_MODE, - false, StateType.checkStation); - } - - /** - * 原_Check2CState 使用这个方法 - */ - final protected void enterIdleAndClearSurveyStateAndCloseAutoMode() { - clearSurveyStateAndCloseAutoModeAndStandStill(CLOSE_AUTO_MODE, false, StateType.idle); - } - - /** - * @param autoMode - * @param clearPosition - * @param stateType - */ - private void clearSurveyStateAndCloseAutoModeAndStandStill(int autoMode, boolean clearPosition, StateType stateType) { - //重置或者关闭自动模式 - if (autoMode == RESET_AUTO_MODE) { - autoModeRecorder().resetAutoMode(); - } else if (autoMode == CLOSE_AUTO_MODE) { - autoModeRecorder().closeAutoMode(); - } - //更新测量进度标识 - if (clearPosition) { - getSurveyorData().clearSurveyStateAndPosition(); - } else { - getSurveyorData().clearSurveyState(); - } - //进入某个状态 - navigation2(stateType); - } - - - /** - * 更新UI - */ - final protected void refreshUI() { - runOnUI(() -> getCachedData().notifyDateChange()); - } - - protected boolean isAutoSurveyOpen() { - return stateManager.isAutoModeOpen(); - } - - protected boolean isAutoSurveyClosed() { - return stateManager.isAutoModeClose(); - } - - double getInsturmentHeight() { - return stateManager.getInsturmentHeight(); - } - - RequestSurveyorParamAuto getRequestSurveyorParamAuto() { - return stateManager.getRequestSurveyorParamAuto(); - } - - protected void refreshGoBack() { - stateManager.refreshGoBackBtnEnable(); - } - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/StateManager.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/StateManager.java deleted file mode 100644 index 4ecd238..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/StateManager.java +++ /dev/null @@ -1,539 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.content.Context; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.WorkerThread; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.point.PointRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.event.RefreshGoBackButton; -import com.bingce.controlapphelper.model.DataCategory; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.AutoSurveyorMethod; -import com.bingce.controlapphelper.surveyor.method.SurveyorAdjustMethod; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.IStateType; -import com.bingce.controlapphelper.surveyor.state.ISurveyState; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyor; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorListener; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyorRemindListener; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParamAuto; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorAutoImpl; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorMockAuto; -import com.bingce.controlapphelper.surveyor.surveyor.SurveyorSingleImpl; -import com.bingce.controlapphelper.surveyor.test.Test; -import com.bingce.controlapphelper.util.DigitalUtil; -import com.bingce.controlapphelper.util.IUIRunner; -import com.bingce.controlapphelper.util.IdUtil; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; -import com.bingce.controlnetwork.fragment.TipsFragment; -import com.bingce.controlnetwork.surveyor.state.AutoModeType; -import com.bingce.controlnetwork.surveyor.state.IScrollDelegate; -import com.bingce.controlnetwork.surveyor.state.StateConstants; -import com.bingce.controlnetwork.surveyor.util.checkadjust.AngleDistanceCheckAdjust; -import com.bingce.controlnetwork.surveyor.util.checkadjust.IStationCheck; -import com.bingce.coordlib.model.Coordinate; -import com.bingce.totalstation.ControlSurveyData; -import com.bingce.totalstation.ControlSurveyResult; -import com.bingce.utils.ThreadPoolUtil; -import com.bingce.utils.VipManager; - -import org.greenrobot.eventbus.EventBus; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import blankj.utilcode.util.ToastUtils; - -public class StateManager implements IAutoModeSwitcher, ISurveyState, IStateType { - private final Map stateMap = new HashMap<>(); - private StateType currentStateType = StateType.idle; - private final FragmentManager fragmentManager; - private final LifecycleOwner lifecycleOwner; - private final IUIRunner iuiRunner; - final IScrollDelegate scrollDelegate; - - @NonNull - SurveyorStationRecord stationRecord; - final @NonNull - RequestSurveyorParamAuto requestSurveyorParamAuto; - final @NonNull - ToleranceDetailRecord toleranceRecord; - final @NonNull - ISurveyorData surveyorData; - final @NonNull - ICachedData cachedData; - final @NonNull - ICycleRecorder cycleRecorder; - final @NonNull - Context context; - private AutoModeType autoMode = AutoModeType.unknown; - @NonNull - final ISurveyor surveyor; - private final PointRecord stationPointRecord; - final boolean supportAutoSurvey; - - private final IStationCheck stationCheck = new AngleDistanceCheckAdjust(); - - private StateManager(final boolean supportAutoSurvey,//是否支持自动测量 - final @NonNull RequestSurveyorParamAuto requestSurveyorParamAuto, - final @NonNull SurveyorStationRecord stationRecord, - final @NonNull PointRecord stationPointRecord, - final @NonNull ToleranceDetailRecord toleranceRecord, - final @NonNull Context context, - final @NonNull ISurveyorData surveyorData, - final @NonNull ICycleRecorder cycleRecorder, - final @NonNull ICachedData cachedData, - final @NonNull IScrollDelegate scrollDelegate, - FragmentManager fragmentManager, - LifecycleOwner lifecycleOwner, - IUIRunner iuiRunner) { - this.supportAutoSurvey = supportAutoSurvey; - - this.requestSurveyorParamAuto = requestSurveyorParamAuto; - this.stationRecord = stationRecord; - this.fragmentManager = fragmentManager; - this.lifecycleOwner = lifecycleOwner; - this.iuiRunner = iuiRunner; - this.scrollDelegate = scrollDelegate; - - this.context = context; - this.toleranceRecord = toleranceRecord; - this.surveyorData = surveyorData; - this.cachedData = cachedData; - this.cycleRecorder = cycleRecorder; - - this.stationPointRecord = stationPointRecord; - - if (Test.DEBUG) { - surveyor = new SurveyorMockAuto(StateConstants.VALUE_MEASURE_WHAT_ANGLE_DISTANCE, this.stationRecord.getId(), - this.stationRecord.isAutoClose(), - toleranceRecord.getCycleCount(), - cachedData, surveyorData, cycleRecorder, this, this); - } else { - if (supportAutoSurvey) { - surveyor = new SurveyorAutoImpl(StateConstants.VALUE_MEASURE_WHAT_ANGLE_DISTANCE, this); - } else { - surveyor = new SurveyorSingleImpl(StateConstants.VALUE_MEASURE_WHAT_ANGLE_DISTANCE); - } - } - _DoSurveyorState doSurveyorState = new _DoSurveyorState(this, this); - //注册接收数据的状态 - surveyor.register((ISurveyorListener) doSurveyorState); - surveyor.register((ISurveyorRemindListener) doSurveyorState); - - stateMap.put(StateType.doSurveyor, doSurveyorState); - stateMap.put(StateType.doAutoSurveyor, new _DoAutoSurveyorState(this, this)); - stateMap.put(StateType.SurveyorFailure, new _SurveyorFailureState(this)); - stateMap.put(StateType.doMove2NextValidate, new _DoMove2NextValidateState(this)); - stateMap.put(StateType.doMoveBack, new _DoMoveBackState(this)); - stateMap.put(StateType.doRecordClean, new _DoRecordCleanState(this)); - stateMap.put(StateType.checkReadData, new _CheckReadDataState(this, this)); - stateMap.put(StateType.isHalfCycleZeroCheckReady, new _IsHalfCycleZeroCheckReadyState(this)); - stateMap.put(StateType.checkHalfCycleZero, new _CheckHalfCycleZeroState(this)); - stateMap.put(StateType.isReady2CCheck, new _Is2CCheckReadyState(this)); - stateMap.put(StateType.check2C, new _Check2CState(this)); - stateMap.put(StateType.isSingleCycleCompleted, new _IsSingleCycleCompletedState(this)); - stateMap.put(StateType.isAllCycleCompleted, new _IsAllCycleCompletedState(this, this)); - stateMap.put(StateType.checkSingleCycle, new _CheckSingleCycleState(this)); - stateMap.put(StateType.checkStation, new _CheckStationState(this)); - stateMap.put(StateType.stationCheckedSuccess, new _CheckStationSuccessState(this)); - - stateMap.put(StateType.doDeleteAllCycle, new _DoDeleteAllCycleState(this)); - stateMap.put(StateType.doDeleteCurrentCycle, new _DoDeleteCurrentCycleState(this)); - - stateMap.put(StateType.doCalScheduleSingleCycle, new _DoCalScheduleInSingleCycleState(this, this)); - stateMap.put(StateType.doCalScheduleAllCycle, new _DoCalScheduleInAllCycleState(this, this)); - stateMap.put(StateType.doCalAdjust, new _DoCalAdjustState(this)); - stateMap.put(StateType.idle, new _IdleState(this, this)); - stateMap.put(StateType.doWellMeasureRotationReady, new _DoWellMeasureRotationReadyState(this)); - - //监听测站数据变化 - runOnUI(() -> SurveyorDatabaseFactory - .instance - .getSurveyorStation() - .getLiveDataRecord(stationRecord.getId()) - .observe(lifecycleOwner, record -> { - if (record == null || !stationRecord.getId().equals(record.getId())) { - return; - } - updateSurveyorStationRecord(record); - })); - } - - private void updateSurveyorStationRecord(SurveyorStationRecord record) { - this.stationRecord = record; - //更新测点信息 - if (stationRecord.getItems() != null) { - for (SurveyorPoint item : stationRecord.getItems()) { - if (item == null || !SurveyorPoint.TYPE_POINT.equals(item.getType())) { - //排除非测点 - continue; - } - cachedData.updateSurveyPointParams(item); - } - } - cachedData.notifyDateChange(); - } - - String stationId() { - return stationRecord.getId(); - } - - - @Override - public void enter(StateType type, Bundle args) { - if (isDead()) { - return; - } - __BaseState baseState = stateMap.get(type); - if (baseState != null) { - this.currentStateType = type; - runOnUI(() -> baseState.enter(args)); - } - } - - @Override - public void enter(StateType type) { - enter(type, null); - } - - void runOnUI(Runnable action) { - if (iuiRunner != null) { - iuiRunner.runOnUI(action); - } - } - - public void doSurveyor() { - boolean inValidate = isInValidate(); - - if (inValidate) { - return; - } - - int pointCount = cachedData.pointCount(); - if (pointCount == 0) { - ToastUtils.showShort(R.string.no_data_available_yet); - return; - } - - Bundle bundle = null; - if (isRotationReadyState()) { - //当前是旋转到位状态 - bundle = new Bundle(); - bundle.putBoolean(StateConstants.KEY_IS_ROTATION_READY_STATE, true); - } - - enter(StateType.doSurveyor, bundle); - } - - public void doAutoSurveyor() { - if (isInValidate()) { - return; - } - enter(StateType.doAutoSurveyor); - } - - public void deleteCurrentStationSurveyorData() { - if (isInValidate()) { - return; - } - enter(StateType.doDeleteAllCycle, _DoDeleteAllCycleState.args(stationId())); - } - - public void deleteCurrentStationSurveyorData(int cycleIndex) { - if (isInValidate()) { - return; - } - enter(StateType.doDeleteCurrentCycle, _DoDeleteCurrentCycleState.args(stationId(), cycleIndex)); - } - - public void stationCheck() { - if (isInValidate()) { - return; - } - enter(StateType.checkStation); - } - - public String stationCheckOnly() { - return stationCheck.check(stationId(), toleranceRecord, cachedData); - } - - public void stationAdjustOnly(String showType) { - ThreadPoolUtil.execute(() -> { - SurveyorAdjustMethod.AdjustResult adjustResult = SurveyorAdjustMethod.calStationAdjust(stationRecord, cachedData); - if (adjustResult.isError()) { - runOnUI(() -> TipsFragment.tipsOnly(fragmentManager, lifecycleOwner, context, adjustResult.errorString)); - return; - } - //显示平差结果 - StationDataAdjustDialogFragment.showDialog(showType, adjustResult.result, adjustResult.showSlopDistance, fragmentManager()); - - //伴随平差 设置进度为通过检测 - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null), - SurveyorScheduleConstants.STATUE_VALUE_CHECKED)); - }); - } - - public void stationAdjust(String type) { - if (isInValidate()) { - return; - } - Bundle bundle = new Bundle(); - bundle.putString(StationDataAdjustDialogFragment.KEY_SHOW_TYPE, type); - enter(StateType.doCalAdjust, bundle); - } - - public void switch2Cycle(int cycleIndex) { - if (isInValidate()) { - return; - } - _DoCalScheduleInSingleCycleState.enter(this, cycleIndex); - } - - public void calScheduleWhenEnterSurveyFragment(int cycleIndex) { - if (isInValidate()) { - return; - } - _DoCalScheduleInAllCycleState.enter(this, cycleIndex); - } - - public void moveBack() { - if (isInValidate()) { - return; - } - enter(StateType.doMoveBack); - } - - //检测当前状态是否支持从外界主动改变状态 - //如果是空闲或者是测站通过检测是有效的状态 - private boolean isInValidate() { - return currentStateType != StateType.idle - && StateType.stationCheckedSuccess != currentStateType - && !isRotationReadyState(); - } - - private boolean isRotationReadyState() { - return currentStateType == StateType.doWellMeasureRotationReady; - } - - public void quite() { - _live = false; - for (Map.Entry entry : stateMap.entrySet()) { - entry.getValue().quite(); - } - //进入idle状态 - this.currentStateType = StateType.idle; - } - - private boolean _live = true; - - boolean isDead() { - return !_live; - } - - public void resume() { - _live = true; - for (Map.Entry entry : stateMap.entrySet()) { - entry.getValue().resume(); - } - } - - FragmentManager fragmentManager() { - return this.fragmentManager; - } - - LifecycleOwner lifecycleOwner() { - return this.lifecycleOwner; - } - - final boolean isStationAutoClosed() { - return stationRecord.isAutoClose(); - } - - @WorkerThread - public static StateManager newInstance( - boolean isSupportAutoMode, - @NonNull RequestSurveyorParamAuto requestSurveyorParamAuto, - @NonNull SurveyorStationRecord stationRecord, - @NonNull Context context, - @NonNull FragmentManager fragmentManager, - @NonNull LifecycleOwner lifecycleOwner, - @NonNull ToleranceDetailRecord toleranceRecord, - @NonNull ISurveyorData surveyorData, - @NonNull ICycleRecorder cycleRecorder, - @NonNull ICachedData cachedData, - IScrollDelegate scrollDelegate, - IUIRunner runner) { - //读取测点record - String stationPointId = null; - if (stationRecord.getItems() != null) { - for (SurveyorPoint stationItem : stationRecord.getItems()) { - if (SurveyorPoint.TYPE_STATION.equals(stationItem.getType())) { - stationPointId = stationItem.getPointId(); - break; - } - } - } - PointRecord stationPointRecord = null; - if (stationPointId != null) { - stationPointRecord = SurveyorDatabaseFactory - .instance - .getPointDataSource() - .findByIdSync(stationPointId); - } - if (stationPointRecord == null) { - return null; - } - boolean supportAuto = Test.DEBUG; - //AppUtils.isAppDebug() - if (isSupportAutoMode && - (VipManager.getInstance().checkReg() || VipManager.getInstance().checkControlProLevel())) { - supportAuto = true; - } - StateManager manager = new StateManager(supportAuto, - requestSurveyorParamAuto, - stationRecord, - stationPointRecord, - toleranceRecord, - context, - surveyorData, - cycleRecorder, - cachedData, - scrollDelegate, - fragmentManager, lifecycleOwner, runner); - return manager; - } - - @Override - public boolean isAutoModeOpen() { - return autoMode == AutoModeType.start; - } - - @Override - public boolean isAutoModeClose() { - return autoMode == AutoModeType.stop; - } - - @Override - public boolean isAutoModeNotSpecial() { - return autoMode == AutoModeType.unknown; - } - - @Override - public void openAutoMode() { - autoMode = AutoModeType.start; - } - - @Override - public void closeAutoMode() { - autoMode = AutoModeType.stop; - } - - @Override - public void resetAutoMode() { - autoMode = AutoModeType.unknown; - } - - - @Override - public int isReadyAutoSurvey() { - if (!supportAutoSurvey) { - return ControlSurveyResult.CODE_ERROR; - } - if (!surveyor.isReady()) {//仪器连接上才算ready - return ControlSurveyResult.CODE_ERROR; - } - - Coordinate stationBasePoint = getStationCoord(); - double instrumentHeight = getInsturmentHeight(); - - return requestSurveyorParamAuto.checkAutoCondition(getCachedData(), stationBasePoint, instrumentHeight); - } - - @Override - public String isMeasuredValueMatchDesign() { - if (!supportAutoSurvey) { - return null; - } - Coordinate stationBasePoint = getStationCoord(); - double instrumentHeight = getInsturmentHeight(); - List originMeasureList = requestSurveyorParamAuto.getOriginMeasureList(getCachedData()); - return AutoSurveyorMethod.checkAutoSurveyorMeasuredValue(stationBasePoint, instrumentHeight, originMeasureList); - } - - @Override - public boolean isSurveying() { - return currentStateType == StateType.doSurveyor || currentStateType == StateType.doAutoSurveyor; - } - - @Override - public boolean isAutoSurveying() { - return isAutoModeOpen(); - } - - - public ICachedData getCachedData() { - return cachedData; - } - - /** - * 获取当前测回 - * - * @return - */ - public int getCurrentCycle() { - return cycleRecorder.currentCycleIndex(); - } - - public int getCurrentIndex() { - return surveyorData.currentIndex(); - } - - private Coordinate getStationCoord() { - if (PointRecord.TYPE_KNOWN_POINT.equals(stationPointRecord.getPointType())) { - return new Coordinate( - stationPointRecord.getX(), - stationPointRecord.getY(), - stationPointRecord.getZ()); - } - return null; - } - - public double getInsturmentHeight() { - return DigitalUtil.valueOfDoubleString(stationRecord.getInstrumentHeight(), 0); - } - - @NonNull - public RequestSurveyorParamAuto getRequestSurveyorParamAuto() { - return requestSurveyorParamAuto; - } - - public void refreshGoBackBtnEnable() { - int currentCycle = cycleRecorder.currentCycleIndex(); - String pointId = getCachedData().pointId(currentCycle, 0); - DataCategory dataCategory = getCachedData().valueState( - IdUtil.createSurveyorRecordId(stationId(), currentCycle, pointId, LeftOrRight.left), 0); - EventBus.getDefault().post(new RefreshGoBackButton(!dataCategory.isEmptyData())); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Check2CState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Check2CState.java deleted file mode 100644 index a1d2566..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_Check2CState.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.ValueOf2cMethod; -import com.bingce.controlapphelper.surveyor.method.model.CacheResult; -import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.utils.Util; - -import net.tatans.tensorflowtts.tts.TtsManager; - -/* - * 检测2c - * */ -class _Check2CState extends __BaseState { - - public _Check2CState(StateManager stateManager) { - super(StateType.check2C, stateManager); - } - - @Override - public void enter(Bundle args) { - String error = _check2C(stationId(), getToleranceRecord(), - getSurveyorData(), - getCycleRecorder().currentCycleIndex(), - getCachedData()); - if (error.isEmpty()) { - navigation2(StateType.doRecordClean); - } else { - if (isAutoSurveyOpen()) { - TtsManager.getInstance().speak(Tools.getString(R.string.erxi_is_over_limit_please_check)); - } - optionTips(error, - Tools.getString(R.string.retest_cycle), - Tools.getString(R.string.retest_point), - () -> optionTipsWithStandStill(Tools.getString(R.string.tips_delete_current_cycle_surveyor_record), - () -> { - String stationId = stationId(); - int currentCycleIndex = getCycleRecorder().currentCycleIndex(); - //删除数据 - ICachedData cachedData = getCachedData(); - cachedData.deleteSurveyorRecord(stationId, currentCycleIndex); - //更新进度 - setSingleCycleSchedule(currentCycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - //重新查找目标开启测量 - findTargetFromBeginInCurrentCycle(true); - }), - this::enterIdleAndClearSurveyState, - this::enterIdleAndClearSurveyStateAndCloseAutoMode); - } - } - - private static String _check2C(String stationId, - ToleranceDetailRecord toleranceRecord, - ISurveyorData surveyorData, - int cycleIndex, - ICachedData cachedData) { - StringBuilder stringBuilder = new StringBuilder(); - - int currentIndex = surveyorData.currentIndex(); - - CacheResult value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.horAngle, currentIndex, stationId, - surveyorData, cycleIndex, cachedData); - - if (!value2C.validate || toleranceRecord.getHor2C() < Math.abs(value2C.value)) { - stringBuilder.append(Tools.getString(R.string.hor_angle_2c_limit)) - .append(toleranceRecord.getHor2C()) - .append("'')\n") - .append(" ") - .append(Tools.getString(R.string.measurements)) - .append(Util.formatDouble2String(Math.abs(value2C.value), 1)) - .append("''"); - } - - value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, currentIndex, stationId, - surveyorData, cycleIndex, cachedData); - if (!value2C.validate || toleranceRecord.getVerI() < Math.abs(value2C.value)) { - stringBuilder.append("\n") - .append(Tools.getString(R.string.ver_angle_i_limit)) - .append(toleranceRecord.getVerI()) - .append("'')\n") - .append(" ") - .append(Tools.getString(R.string.measurements)) - .append(Util.formatDouble2String(Math.abs(value2C.value), 1)) - .append("''"); - } - - if (!cachedData.isAloneDistance(cycleIndex, surveyorData.currentIndex())) { - value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.distance, currentIndex, stationId, - surveyorData, cycleIndex, cachedData); - if (!value2C.validate || toleranceRecord.getSlopeLensDistanceDifference() < Math.abs(value2C.value)) { - stringBuilder.append("\n") - .append(Tools.getString(R.string.distance_positive_and_negative_mirror_limit)) - .append(toleranceRecord.getSlopeLensDistanceDifference()) - .append("mm)\n") - .append(" ") - .append(Tools.getString(R.string.measurements)) - .append(Util.formatDouble2String(Math.abs(value2C.value), 1)) - .append("mm"); - } - } - - return stringBuilder.toString(); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckReadDataState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckReadDataState.java deleted file mode 100644 index 4d64557..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckReadDataState.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.DeviationValueOfRadianMethod; -import com.bingce.controlapphelper.surveyor.method.RadianMethod; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.totalstation.TotalStation; - -import net.tatans.tensorflowtts.tts.TtsManager; - - -/* - * 检测当前测量数据读数互差 - * */ -class _CheckReadDataState extends __BaseState { - private static final int RESULT_SUCCESS = 0; - private static final int RESULT_FAILURE_HOR = 1; - private static final int RESULT_FAILURE_VER = 2; - private static final int RESULT_FAILURE_DISTANCE = 3; - private final IAutoModeSwitcher autoModeSwitcher; - - public _CheckReadDataState(StateManager stateManager, IAutoModeSwitcher autoModeSwitcher) { - super(StateType.checkReadData, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - //先检测测量值和设计值是否匹配(仅在自动测量打开下检测) - String error = autoModeSwitcher.isMeasuredValueMatchDesign(); - if (error != null) { - failureTipsWithAutoStandStill(error); - return; - } - int surveyorCount = getToleranceRecord().getSurveyorCount(); - if (surveyorCount <= 1) {//单次测量,直接通过检测 - onCompleted(RESULT_SUCCESS); - } else {//多次测量,执行检测 - ISurveyorData surveyorDataSource = getSurveyorData(); - double horDifference = getToleranceRecord().getHorReadDifference(); - double verDifference = getToleranceRecord().getVerReadDifference(); - double distanceDifference = getToleranceRecord().getSlopeReadDifference(); - double horDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff(surveyorDataSource.getAngleHor1(), surveyorDataSource.getAngleHor2()); - double verDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff(surveyorDataSource.getAngleVer1(), surveyorDataSource.getAngleVer2()); - - int resultCode = RESULT_SUCCESS; - if (horDifference < RadianMethod.radian2S(horDiffRadian)) { - resultCode = RESULT_FAILURE_HOR; - } else if (verDifference < RadianMethod.radian2S(verDiffRadian)) { - resultCode = RESULT_FAILURE_VER; - } else if (!isAloneDistance()//增加单独测距判断 - && distanceDifference < distanceReadDiff(surveyorDataSource.getDistance1(), surveyorDataSource.getDistance2())) { - resultCode = RESULT_FAILURE_DISTANCE; - } - onCompleted(resultCode); - } - } - - private void onCompleted(int result) { - if (RESULT_SUCCESS == result) { - checkLeft(); - } else { - String msg = ""; - switch (result) { - case RESULT_FAILURE_HOR: - msg = Tools.getString(R.string.hor_angle_read_data_limit); - break; - case RESULT_FAILURE_VER: - msg = Tools.getString(R.string.ver_angle_read_data_limit); - break; - case RESULT_FAILURE_DISTANCE: - msg = Tools.getString(R.string.distance_read_data_limit); - break; - default: - navigation2(StateType.idle); - return; - } - if (isAutoSurveyOpen()) { - TtsManager.getInstance().speak(msg); - } - failureTipsWithAutoStandStill(msg); - } - } - - /** - * 如果是测回内首次测量,需要判断是否是盘左 - */ - private void checkLeft() { - int currentItem = getSurveyorData().currentIndex(); - LeftOrRight leftOrRight = getSurveyorData().leftOrRight(); - if (leftOrRight == LeftOrRight.left) { - //如果是首次测量,强制要求使用盘左 - double vAngle = getSurveyorData().getAngleVer(); - if (!isFirstValidate(vAngle)) { - failureTipsWithAutoStandStill( - getContext().getString(R.string.error_tips_please_start_from_left), - () -> { - TotalStation.getInstance().requestChangeFace(); - }); - return; - } - } - navigation2(StateType.isHalfCycleZeroCheckReady); - } - - private boolean isFirstValidate(double vAngle) { - return vAngle >= 0 && vAngle <= Math.PI; - } - - /** - * 斜距两次读数差 - * - * @param distance1 读数1 - * @param distance2 读数2 - * @return 读数差(单位毫米) - */ - public static double distanceReadDiff(double distance1, double distance2) { - return Math.abs(distance1 - distance2) * 1000; - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationState.java deleted file mode 100644 index 75e2aaa..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_CheckStationState.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import androidx.annotation.WorkerThread; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.point.IPointDataSource; -import com.bingce.controlapphelper.datasource.database.point.PointRecord; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.surveyorstation.ISurveyorStationDataSource; -import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.fragment.SelectReSurveyorPointFragment; -import com.bingce.controlnetwork.surveyor.util.checkadjust.AngleDistanceCheckAdjust; -import com.bingce.controlnetwork.surveyor.util.checkadjust.IStationCheck; -import com.bingce.utils.ThreadPoolUtil; - -import java.util.ArrayList; -import java.util.List; - -/** - * 执行「测站检测」 - *

- * 前置条件: - * 所有测回都完成测量,并且通过「测回内检测」 - */ -class _CheckStationState extends __BaseState { - - private final IStationCheck stationCheck = new AngleDistanceCheckAdjust(); - - public _CheckStationState(StateManager stateManager) { - super(StateType.checkStation, stateManager); - } - - @Override - public void enter(Bundle args) { - //执行测站检测 - String error = stationCheck.check(stationId(), getToleranceRecord(), getCachedData()); - if (error == null || error.isEmpty()) { - //进入finish状态 - navigation2(StateType.stationCheckedSuccess); - } else { - showErrorTips(error, stationId(), getToleranceRecord().getCycleCount(), - getSurveyorData(), getCycleRecorder(), getCachedData(), - this, - fragmentManager(), - lifecycleOwner()); - } - } - - /** - * 提示错误信息,并让用户选择下一步操作 - */ - static void showErrorTips(String msg, String stationId, int cycleCount, - ISurveyorData surveyorDataSource, - ICycleRecorder cycleRecorder, - ICachedData stationSurveyorDataSource, - __BaseState state, - FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { - state.optionTips(msg, - Tools.getString(R.string.retest_direction), - Tools.getString(R.string.retest_station), - () -> state.runOnBackground(() -> reSurveyorPoint(stationId, cycleCount, - cycleRecorder, stationSurveyorDataSource, - state, fragmentManager, lifecycleOwner)), - () -> reSurveyorStation(msg, stationId, cycleCount, - surveyorDataSource, cycleRecorder, stationSurveyorDataSource, - state, fragmentManager, lifecycleOwner), - () -> state.enterIdleAndClearSurveyStateAndResetAutoMode(true)); - } - - @WorkerThread - static void reSurveyorPoint(String stationId, int cycleCount, - ICycleRecorder cycleRecorder, - ICachedData cachedData, - __BaseState state, - FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { - //弹框提示选择重测数据 - ISurveyorStationDataSource dataSource = SurveyorDatabaseFactory.instance.getSurveyorStation(); - SurveyorStationRecord instance = dataSource.getRecordSync(stationId); - if (instance == null) { - state.enterIdleAndClearSurveyStateAndResetAutoMode(true); - return; - } - IPointDataSource pointDataSource = SurveyorDatabaseFactory.instance.getPointDataSource(); - List stationItems = instance.getItems(); - ArrayList ids = new ArrayList<>(); - ArrayList names = new ArrayList<>(); - for (SurveyorPoint item : stationItems) { - if (item.isAbandon()) { - continue; - } - - if (!SurveyorPoint.TYPE_POINT.equals(item.getType())) { - continue; - } - PointRecord pointRecord = pointDataSource.findByIdSync(item.getPointId()); - if (pointRecord == null) { - continue; - } - ids.add(pointRecord.id); - names.add(pointRecord.name); - } - state.runOnUI(() -> SelectReSurveyorPointFragment.pick( - fragmentManager, - lifecycleOwner, - cycleCount, - instance.leftAndRightSurveyor, - ids, - names, - (cycleIndex, pointIds) -> { - if (pointIds == null || pointIds.isEmpty()) { - state.enterIdleAndClearSurveyStateAndResetAutoMode(true); - } else { - //记录补测数据类型,切换测回 - cachedData.markReSurveyor(stationId, cycleIndex, pointIds); - cycleRecorder.changeCycleIndex(cycleIndex); - - //更新测量状态 - state.setCurrentCycle(cycleIndex); - state.setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - state.setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - - //查找新测量目标 - state.findTargetFromBeginInCurrentCycle(true); - } - } - )); - } - - static void reSurveyorStation(String msg, String stationId, int cycleCount, - ISurveyorData surveyorData, - ICycleRecorder cycleRecorder, - ICachedData cachedData, - __BaseState state, - FragmentManager fragmentManager, LifecycleOwner lifecycleOwner) { - state.optionTips(Tools.getString(R.string.is_delete_all_station_data), null, null, - () -> {//1.选择删除测站所有数据,则执行相应逻辑 - ThreadPoolUtil.execute(() -> { - //删除数据 - cachedData.deleteSurveyorRecord(stationId); - - //更新测量进度 - state.setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - for (int index = 0; index < cycleCount; index++) { - state.setSingleCycleSchedule(index, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - } - - state.resetLearnDataTag(); - - //重新测量 - state.findTargetFromBeginInCurrentCycle(true); - }); - }, - () -> {//2.如果用户不选择删除,则循环提示,让他重新在重测和删除做选择 - //循环显示 - showErrorTips(msg, stationId, cycleCount, - surveyorData, cycleRecorder, cachedData, state, - fragmentManager, lifecycleOwner); - }, - () -> state.enterIdleAndClearSurveyStateAndResetAutoMode(true));//3.如果用户忽略,则停留在当前位置 - } - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoAutoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoAutoSurveyorState.java deleted file mode 100644 index 499830a..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoAutoSurveyorState.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.totalstation.ControlSurveyResult; - -import net.tatans.tensorflowtts.tts.TtsManager; - -/** - * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 - */ -class _DoAutoSurveyorState extends __BaseState { - private final IAutoModeSwitcher autoModeSwitcher; - - public _DoAutoSurveyorState(StateManager stateManager, IAutoModeSwitcher autoModeSwitcher) { - super(StateType.doAutoSurveyor, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - if (autoModeSwitcher.isReadyAutoSurvey() == ControlSurveyResult.CODE_SUCCESS) { - autoModeSwitcher.openAutoMode(); - navigation2(StateType.doMove2NextValidate); - TtsManager.getInstance().speak(Tools.getString(R.string.start_auto_measure)); - } - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalAdjustState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalAdjustState.java deleted file mode 100644 index bbbabf6..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoCalAdjustState.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.surveyor.method.SurveyorAdjustMethod; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlnetwork.fragment.StationDataAdjustDialogFragment; - -/** - * 平差计算 - */ -public class _DoCalAdjustState extends __BaseState { - - public _DoCalAdjustState(StateManager stateManager) { - super(StateType.doCalAdjust, stateManager); - } - - @Override - public void enter(Bundle args) { - String showType = null; - if (args != null) { - showType = args.getString(StationDataAdjustDialogFragment.KEY_SHOW_TYPE); - } - startCalAdjust(showType); - } - - private void startCalAdjust(String showType) { - runOnBackground(() -> { - SurveyorAdjustMethod.AdjustResult adjustResult = SurveyorAdjustMethod.calStationAdjust(getStation(), getCachedData()); - if (adjustResult.isError()) { - runOnUI(() -> _CheckStationState.showErrorTips(adjustResult.errorString, stationId(), getToleranceRecord().getCycleCount(), - getSurveyorData(), getCycleRecorder(), getCachedData(), - _DoCalAdjustState.this, - fragmentManager(), - lifecycleOwner())); - return; - } - //清除测量状态,进入idle,停止自动测量 - enterIdleAndClearSurveyStateAndResetAutoMode(true); - StationDataAdjustDialogFragment.showDialog(showType, adjustResult.result, adjustResult.showSlopDistance, fragmentManager()); - } - ); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteAllCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteAllCycleState.java deleted file mode 100644 index c687f54..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteAllCycleState.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.config.ConfigConstants; -import com.bingce.controlapphelper.datasource.database.config.IConfigDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.utils.ThreadPoolUtil; - -import com.bingce.controlnetwork.R; - -/* - * 删除本测站所有测回数据 - * */ -class _DoDeleteAllCycleState extends __BaseState { - - private static final String KEY_STATION_ID = "__station_id"; - - static Bundle args(String stationId) { - Bundle args = new Bundle(); - args.putString(KEY_STATION_ID, stationId); - return args; - } - - public _DoDeleteAllCycleState(StateManager stateManager) { - super(StateType.doDeleteAllCycle, stateManager); - } - - @Override - public void enter(Bundle args) { - String stationId = args.getString(KEY_STATION_ID); - - optionTipsWithStandStill(getContext().getString(R.string.tips_delete_station_all_surveyor_records), - () -> deleteAllCycleData(stationId)); - } - - private void deleteAllCycleData(String stationId) { - ThreadPoolUtil.execute(() -> { - //删除数据 - ICachedData cachedData = getCachedData(); - cachedData.deleteSurveyorRecord(stationId); - - //清除已经提示测站可以检测标识 - IConfigDataSource configDataSource = - SurveyorDatabaseFactory.instance.getConfigDataSource(); - String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId; - configDataSource.setSync(key, ConfigConstants.VALUE_NO); - - //重置进度 - setAllCycleScheduleSync(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - for (int cycleIndex = 0; cycleIndex < getToleranceRecord().getCycleCount(); cycleIndex++) { - setSingleCycleScheduleSync(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - } - - //重置学习测量的标志 - resetLearnDataTag(); - - //从第一测回开始 - setCurrentCycleSync(0); - - //重新测量,并刷新 - findTargetFromBeginInCurrentCycle(true); - }); - } - - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteCurrentCycleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteCurrentCycleState.java deleted file mode 100644 index 6fa1af8..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoDeleteCurrentCycleState.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.config.ConfigConstants; -import com.bingce.controlapphelper.datasource.database.config.IConfigDataSource; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.utils.ThreadPoolUtil; - -import com.bingce.controlnetwork.R; - -class _DoDeleteCurrentCycleState extends __BaseState { - - private static final String KEY_STATION_ID = "__station_id"; - private static final String KEY_PERIOD_INDEX = "__period_index__"; - - static Bundle args(String stationId, int periodIndex) { - Bundle args = new Bundle(); - args.putString(KEY_STATION_ID, stationId); - args.putInt(KEY_PERIOD_INDEX, periodIndex); - return args; - } - - public _DoDeleteCurrentCycleState(StateManager stateManager) { - super(StateType.doDeleteCurrentCycle, stateManager); - } - - @Override - public void enter(Bundle args) { - String stationId = args.getString(KEY_STATION_ID); - int cycleIndex = args.getInt(KEY_PERIOD_INDEX); - - optionTipsWithStandStill(getContext().getString(R.string.tips_delete_current_cycle_surveyor_record), - () -> deleteSingleCycle(stationId, cycleIndex)); - } - - private void deleteSingleCycle(String stationId, int cycleIndex) { - ThreadPoolUtil.execute(() -> { - //删除数据 - ICachedData stationSurveyorDataSource = getCachedData(); - stationSurveyorDataSource.deleteSurveyorRecordSync(stationId, cycleIndex); - - //清除已经提示测站可以检测标识 - IConfigDataSource configDataSource = SurveyorDatabaseFactory.instance.getConfigDataSource(); - String key = ConfigConstants.KEY_CONFIG_STATION_CHECK_REMINDED + stationId; - configDataSource.setSync(key, ConfigConstants.VALUE_NO); - - //设置当前测回 - setCurrentCycleSync(cycleIndex); - //重置所有测回和当次测回进度 - setAllCycleScheduleSync(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setSingleCycleScheduleSync(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - - if (cycleIndex == 0) { - //当第一测回 - //重置学习测量的标志 - resetLearnDataTag(); - } - - //重新测量,并刷新 - findTargetFromBeginInCurrentCycle(true); - }); - - } - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoRecordCleanState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoRecordCleanState.java deleted file mode 100644 index 222fbc8..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoRecordCleanState.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.model.DataCategory; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.state.StateType; - -/** - * 记录测量数据 - */ -class _DoRecordCleanState extends __BaseState { - public _DoRecordCleanState(StateManager stateManager) { - super(StateType.doRecordClean, stateManager); - } - - @Override - public void enter(Bundle args) { - ICachedData cacheData = getCachedData(); - ISurveyorData surveyorData = getSurveyorData(); - ICycleRecorder cycleRecorder = getCycleRecorder(); - //设置数据正常 - surveyorData.setDataCategory(DataCategory.normalCategory()); - //存储(缓存+数据库) - cacheData.cache(cycleRecorder.currentCycleIndex(), surveyorData); - - //检测单测回是否完成 - navigation2(StateType.isSingleCycleCompleted); - } -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoWellMeasureRotationReadyState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoWellMeasureRotationReadyState.java deleted file mode 100644 index 9bdbde8..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_DoWellMeasureRotationReadyState.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import com.bingce.controlapphelper.event.AutoSurveyorButtonVisibleEvent; -import com.bingce.controlapphelper.event.SurveyStateEvent; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlnetwork.R; - -import net.tatans.tensorflowtts.tts.TtsManager; - -import org.greenrobot.eventbus.EventBus; - -/** - * 钢丝测量旋转到位状态 - */ -class _DoWellMeasureRotationReadyState extends __BaseState { - - public _DoWellMeasureRotationReadyState(StateManager stateManager) { - super(StateType.doWellMeasureRotationReady, stateManager); - } - - @Override - public void enter(Bundle args) { - runOnUI(() -> TtsManager.getInstance().speak(getContext().getString(R.string.please_aiming_at_alone_distance_point_then_measure))); - SurveyStateEvent.postIdle(positionFragment); - EventBus.getDefault().post(new AutoSurveyorButtonVisibleEvent(positionFragment, false, true)); - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IdleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IdleState.java deleted file mode 100644 index 0606880..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/_IdleState.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.os.Bundle; - -import androidx.annotation.NonNull; - -import com.bingce.controlapphelper.event.AutoSurveyorButtonVisibleEvent; -import com.bingce.controlapphelper.event.SurveyStateEvent; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.totalstation.ControlSurveyResult; -import com.bingce.utils.ThreadPoolUtil; - -import net.tatans.tensorflowtts.tts.TtsManager; - -import org.greenrobot.eventbus.EventBus; - -import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; - -/** - * 空闲状态 - *

- * 将刷新界面 - */ -class _IdleState extends __BaseState { - private final @NonNull - IAutoModeSwitcher autoModeSwitcher; - - public _IdleState(StateManager stateManager, @NonNull IAutoModeSwitcher autoModeSwitcher) { - super(StateType.idle, stateManager); - this.autoModeSwitcher = autoModeSwitcher; - } - - @Override - public void enter(Bundle args) { - //1.刷新界面 - refreshUI(); - - refreshGoBackBtnEnable(); - - //3.当前cycle是否完成测量 - boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( - stationId(), - getCycleRecorder().currentCycleIndex(), - getCachedData()); - //4.检测是否满足自动测量条件 - ThreadPoolUtil.execute(() -> { - //判断当前条件是否满足自动测量 - - boolean haveAutoCondition = haveAutoCondition(); - - if (haveAutoCondition && autoModeSwitcher.isAutoModeOpen() && isLive()) { - navigation2(StateType.doSurveyor); - } else if (haveAutoCondition && autoModeSwitcher.isAutoModeNotSpecial() && !completed) { - //用户选择后会发送通知,更新测量按钮UI - tips4StartAutoSurvey(); - } else { -// ControlSurveyResult.isAbandon(autoMeasureReadyCode) != null//这个错误 - if (autoModeSwitcher.isAutoModeOpen()) { - autoModeSwitcher.resetAutoMode(); - } - postEvent(haveAutoCondition, autoModeSwitcher.isAutoModeOpen(), completed); - } - - }); - } - - /** - * 弹框提示用户是否开启自动测量 - */ - private void tips4StartAutoSurvey() { - runOnUI(() -> - TipsWith2OptionFragment.hardTips( - fragmentManager(), - lifecycleOwner(), - getContext().getString(R.string.tips_finish_study_should_auto_survey), - new TipsWith2OptionFragment.SimpleCallback() { - @Override - public void onConfirm() { - TtsManager.getInstance().speak(Tools.getString(R.string.start_auto_measure)); - autoModeSwitcher.openAutoMode(); - navigation2(StateType.doSurveyor); - - postEvent(true, true, false); - } - - @Override - public void onCancel() { - autoModeSwitcher.closeAutoMode(); - - postEvent(true, false, false); - } - - @Override - public void onIgnore() { - autoModeSwitcher.closeAutoMode(); - - postEvent(true, false, false); - } - } - )); - } - - private void postEvent(boolean isReadyAutoSurvey, boolean isOpenAutoSurvey, boolean isSingleCompleted) { - EventBus.getDefault().post(new AutoSurveyorButtonVisibleEvent(positionFragment, isReadyAutoSurvey, isOpenAutoSurvey)); - if (isSingleCompleted) { - SurveyStateEvent.postCompleted(positionFragment); - } else if (!isOpenAutoSurvey) { - SurveyStateEvent.postIdle(positionFragment); - } - } - - @Override - protected void resume() { - autoModeSwitcher.resetAutoMode(); - //刷新测量按钮 - boolean completed = _IsSingleCycleCompletedState.isSingleCycleCompleted( - stationId(), - getCycleRecorder().currentCycleIndex(), - getCachedData()); - boolean isReady = autoModeSwitcher.isReadyAutoSurvey() == ControlSurveyResult.CODE_SUCCESS; - - postEvent(isReady, false, completed); - } - - private boolean haveAutoCondition() { - int autoMeasureReadyCode = autoModeSwitcher.isReadyAutoSurvey(); - return autoMeasureReadyCode == ControlSurveyResult.CODE_SUCCESS; - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/__BaseState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/__BaseState.java deleted file mode 100644 index a4dfef3..0000000 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/angledistance/__BaseState.java +++ /dev/null @@ -1,586 +0,0 @@ -package com.bingce.controlnetwork.surveyor.state.angledistance; - -import android.content.Context; -import android.os.Bundle; -import android.text.TextUtils; - -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.LifecycleOwner; - -import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleConstants; -import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; -import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; -import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; -import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.model.IStateDelegate; -import com.bingce.controlapphelper.surveyor.state.IAutoModeSwitcher; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.surveyor.surveyor.ISurveyor; -import com.bingce.controlapphelper.surveyor.surveyor.RequestSurveyorParamAuto; -import com.bingce.controlapphelper.util.SurveyorCycleUtil; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; -import com.bingce.controlnetwork.fragment.TipsFragment; -import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; -import com.bingce.controlnetwork.fragment.stationsurvey.angledistance.MeasureFragment; -import com.bingce.utils.ThreadPoolUtil; - -import java.util.List; - -import blankj.utilcode.util.ToastUtils; - -public abstract class __BaseState { - private final StateType type; - private final StateManager stateManager; - - protected final int positionFragment = MeasureFragment.POSITION_DIRECTION_MEASURE; - - /** - * 判断常量 - */ - private final int DEFAULT_AUTO_MODE = 0; - private final int RESET_AUTO_MODE = 1; - private final int CLOSE_AUTO_MODE = 2; - - public __BaseState(final StateType stateType, final StateManager stateManager) { - this.type = stateType; - this.stateManager = stateManager; - } - - final protected StateType getType() { - return type; - } - - final protected @NonNull - ToleranceDetailRecord getToleranceRecord() { - return stateManager.toleranceRecord; - } - - final protected @NonNull - ISurveyorData getSurveyorData() { - return stateManager.surveyorData; - } - - private @NonNull - IAutoModeSwitcher autoModeRecorder() { - return stateManager; - } - - /** - * 设置测量位置 - */ - final protected void setSurveyPosition(int index, LeftOrRight leftOrRight) { - stateManager.surveyorData.setCurrentIndex(index); - stateManager.surveyorData.setLeftOrRight(leftOrRight); - //新增 - if (isAloneDistance()) - ToastUtils.showShort(getContext().getString(R.string.attention_point_is_alone_distance)); - } - - final protected ISurveyor surveyorImpl() { - return stateManager.surveyor; - } - - final protected @NonNull - ICachedData getCachedData() { - return stateManager.cachedData; - } - - SurveyorStationRecord getStation() { - return stateManager.stationRecord; - } - - RequestSurveyorParamAuto getRequestSurveyorParamAuto() { - return stateManager.getRequestSurveyorParamAuto(); - } - - void changeSkip(int cycleIndex, int index) { - SurveyorStationRecord station = getStation(); - //缓存点 - getCachedData().setPointAbandon(cycleIndex, index); - //数据库点 - String pointId = getCachedData().originalPointId(cycleIndex, index); - for (SurveyorPoint surveyorPoint : station.items) { - if (TextUtils.equals(pointId, surveyorPoint.getOriginalPointId())) { - surveyorPoint.setAbandon(true); - break; - } - } - ThreadPoolUtil.execute(() -> { - SurveyorDatabaseFactory.instance.getSurveyorStation().update(station); - }); - } - - final protected @NonNull - ICycleRecorder getCycleRecorder() { - return stateManager.cycleRecorder; - } - - final protected @NonNull - Context getContext() { - return stateManager.context; - } - - final protected void scroll2(int itemIndex) { - stateManager.scrollDelegate.onScrollTo(itemIndex); - } - - final protected void toast(String warning) { - ToastUtils.showShort(warning); - } - - final protected void toast(@StringRes int warning) { - ToastUtils.showShort(warning); - } - - public abstract void enter(Bundle args);//进入状态 - - final protected void navigation2(StateType stateType) { - stateManager.enter(stateType); - } - - final protected void navigation2(StateType stateType, Bundle args) { - stateManager.enter(stateType, args); - } - - final boolean isStationClosed() { - return stateManager.isStationAutoClosed(); - } - - final protected String stationId() { - return stateManager.stationId(); - } - - final protected FragmentManager fragmentManager() { - return stateManager.fragmentManager(); - } - - final protected LifecycleOwner lifecycleOwner() { - return stateManager.lifecycleOwner(); - } - - final protected void tips(String msg, Runnable runnable) { - if (stateManager.isDead()) { - return; - } - TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), - getContext(), - msg, - -1, - () -> { - if (runnable != null) { - runnable.run(); - } - }); - } - - /** - * 错误提示 - *

- * 用户不能忽略,点击确定后自动「停留原地」 - */ - final protected void failureTipsWithAutoStandStill(String msg) { - if (stateManager.isDead()) { - return; - } - TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), - getContext(), - msg, - -1, - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); - } - - final protected void failureTipsWithAutoStandStill(String msg, Runnable runnable) { - if (stateManager.isDead()) { - return; - } - TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), - getContext(), - msg, - -1, - () -> { - runnable.run(); - enterIdleAndClearSurveyStateAndResetAutoMode(true); - }); - } - - final protected void optionTipsWithStandStill(String msg, Runnable confirmCallback) { - optionTips(msg, null, null, - confirmCallback, - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); - } - - final protected void optionTips(String msg, - String confirmButton, - String cancelButton, - Runnable confirmCallback, - Runnable cancelCallback, - Runnable ignoreCallback) { - if (stateManager.isDead()) { - return; - } - TipsWith2OptionFragment.tips( - stateManager.fragmentManager(), - stateManager.lifecycleOwner(), - confirmButton, - cancelButton, - null, - msg, - new TipsWith2OptionFragment.IOperatorCallback() { - @Override - public void onConfirm() { - if (confirmCallback == null) { - return; - } - confirmCallback.run(); - } - - @Override - public void onCancel() { - if (cancelCallback == null) { - return; - } - cancelCallback.run(); - } - - @Override - public void onIgnore() { - if (ignoreCallback == null) { - return; - } - ignoreCallback.run(); - } - - @Override - public void onOption() { - } - }); - } - - final protected void optionTipsCountDown(String msg, - String confirmButton, - String cancelButton, - Runnable confirmCallback, - Runnable cancelCallback, - Runnable ignoreCallback) { - if (stateManager.isDead()) { - return; - } - - TipsWith2OptionFragment.tipsCountDownTime( - stateManager.fragmentManager(), - stateManager.lifecycleOwner(), - confirmButton, - cancelButton, - null, - msg, - new TipsWith2OptionFragment.IOperatorCallback() { - @Override - public void onConfirm() { - if (confirmCallback == null) { - return; - } - confirmCallback.run(); - } - - @Override - public void onCancel() { - if (cancelCallback == null) { - return; - } - cancelCallback.run(); - } - - @Override - public void onIgnore() { - if (ignoreCallback == null) { - return; - } - ignoreCallback.run(); - } - - @Override - public void onOption() { - } - }); - } - - protected final void option4Jump2OtherCycle4Resurvey(int cycleIndex) { - option4Jump2OtherCycle(cycleIndex, true); - } - - protected final void option4Jump2OtherEmptyCycle(int cycleIndex) { - option4Jump2OtherCycle(cycleIndex, false); - } - - private void option4Jump2OtherCycle(int cycleIndex, boolean resurveyOrEmpty) { - String msg = Tools.getString(R.string.there_is_empty_data_to_be_tested_hint); - if (resurveyOrEmpty) { - msg = Tools.getString(R.string.there_is_supplementary_data_to_be_tested_hint); - } - optionTips(Tools.getString(R.string.at) + SurveyorCycleUtil.cycleName(cycleIndex) + msg, - null, - null, - () -> { - //切换测回 - getCycleRecorder().changeCycleIndex(cycleIndex); - //数据库存储修改当前测回 - setCurrentCycle(cycleIndex); - //查找测量目标 - findTargetFromBeginInCurrentCycle(false); - }, - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), - () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); - } - - final protected void runOnUI(Runnable runnable) { - stateManager.runOnUI(runnable); - } - - final protected void runOnBackground(Runnable runnable) { - ThreadPoolUtil.execute(runnable); - } - - /** - * 设置测站的测回 - * - * @param cycle - */ - final protected void setCurrentCycle(int cycle) { - getCycleRecorder().changeCycleIndex(cycle); - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getCurrentCycleKey(stationId(), null), - String.valueOf(cycle))); - } - - final protected void setCurrentCycleSync(int cycle) { - getCycleRecorder().changeCycleIndex(cycle); - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .recordSync( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getCurrentCycleKey(stationId(), null), - String.valueOf(cycle))); - } - - final protected void setSingleCycleSchedule(int cycleIndex, String schedule) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getSingleCycleScheduleKey(stationId(), null, cycleIndex), - schedule)); - } - - final protected void setSingleCycleScheduleSync(int cycleIndex, String schedule) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .recordSync( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getSingleCycleScheduleKey(stationId(), null, cycleIndex), - schedule)); - } - - final protected void setAllCycleSchedule(String schedule) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .record( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null), - schedule)); - } - - final protected void setAllCycleScheduleSync(String schedule) { - SurveyorDatabaseFactory - .instance - .getScheduleDataSource() - .recordSync( - new SurveyorScheduleRecord( - SurveyorScheduleConstants.getAllCycleScheduleKey(stationId(), null), - schedule)); - } - - /** - * 如果resetAutoSurveyState为true,将重置autoSurvey状态为unknown - */ - final protected void findTargetFromBeginInCurrentCycle(boolean resetAutoSurveyState) { - getSurveyorData().clearSurveyStateAndPosition(); - if (resetAutoSurveyState) { - autoModeRecorder().resetAutoMode(); - } - navigation2(StateType.doMove2NextValidate); - } - - final protected void enterIdleAndClearSurveyState() { - clearSurveyStateAndCloseAutoModeAndStandStill(DEFAULT_AUTO_MODE, - false, StateType.idle); - } - - /** - * 取消测量,会停在当前位置(索引+盘左or盘右),并进入idle - */ - final protected void enterIdleAndClearSurveyStateAndResetAutoMode(boolean resetAutoMode) { - clearSurveyStateAndCloseAutoModeAndStandStill(resetAutoMode ? RESET_AUTO_MODE : DEFAULT_AUTO_MODE, - false, StateType.idle); - } - - final protected void enterIdleAndClearSurveyorStatePosition() { - clearSurveyStateAndCloseAutoModeAndStandStill(DEFAULT_AUTO_MODE, - true, StateType.idle); - } - - final protected void enterStationCheckAndClearSurveyStateAndResetAutoMode() { - clearSurveyStateAndCloseAutoModeAndStandStill(RESET_AUTO_MODE, - false, StateType.checkStation); - } - - final protected void enterIdleAndClearSurveyStateAndCloseAutoMode() { - clearSurveyStateAndCloseAutoModeAndStandStill(CLOSE_AUTO_MODE, false, StateType.idle); - } - - /** - * @param autoMode - * @param clearPosition - * @param stateType - */ - private void clearSurveyStateAndCloseAutoModeAndStandStill(int autoMode, boolean clearPosition, StateType stateType) { - //重置或者关闭自动模式 - if (autoMode == RESET_AUTO_MODE) { - autoModeRecorder().resetAutoMode(); - } else if (autoMode == CLOSE_AUTO_MODE) { - autoModeRecorder().closeAutoMode(); - } - //更新测量进度标识 - if (clearPosition) { - getSurveyorData().clearSurveyStateAndPosition(); - } else { - getSurveyorData().clearSurveyState(); - } - //进入某个状态 - navigation2(stateType); - } - - - /** - * 更新UI - */ - final protected void refreshUI() { - runOnUI(() -> getCachedData().notifyDateChange()); - } - - protected void quite() { - } - - protected void resume() { - } - - protected boolean isLive() { - return !stateManager.isDead(); - } - - protected boolean isAutoSurveyOpen() { - return stateManager.isAutoModeOpen(); - } - - protected boolean isAutoSurveyClosed() { - return stateManager.isAutoModeClose(); - } - - protected IStateDelegate stateDelegate() { - return new IStateDelegate() { - @Override - public void onOptionTips( - String msg, String confirmButton, String cancelButton, - Runnable confirmCallback, Runnable cancelCallback, Runnable ignoreCallback) { - optionTips( - msg, confirmButton, cancelButton, - confirmCallback, cancelCallback, ignoreCallback); - } - - @Override - public void resetSurveyorStateAndKeepPosition() { - //关闭自动测量 - autoModeRecorder().resetAutoMode(); - //更新测量进度标识 - getSurveyorData().clearSurveyState(); - //进入空闲状态 - navigation2(StateType.idle); - } - - @Override - public void resurveyPoints(int cycleIndex, List pointIds) { - if (cycleIndex == -1) { - cycleIndex = getCycleRecorder().currentCycleIndex(); - } - - //更新记录数据,包括将数据置为dirty和切换cycle - getCachedData().markReSurveyor(stationId(), cycleIndex, pointIds); - getCycleRecorder().changeCycleIndex(cycleIndex); - - //根据当前状态,查找一个目标 - findTargetFromBeginInCurrentCycle(true); - - //更新数据库标识 - setCurrentCycle(cycleIndex); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - } - - @Override - public void deleteSingleCycleData(int cycleIndex) { - //删除数据 - getCachedData().deleteSurveyorRecord(stationId(), cycleIndex); - //切换测回--一般不用,但是这里为了保险 - getCycleRecorder().changeCycleIndex(cycleIndex); - //查找一个新目标开启测量 - findTargetFromBeginInCurrentCycle(true); - - //更新数据库标识 - setCurrentCycle(cycleIndex); - setAllCycleSchedule(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - setSingleCycleSchedule(cycleIndex, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); - } - }; - } - - protected int getCurrentIndex() { - return stateManager.surveyorData.currentIndex(); - } - - protected int getCurrentCycleIndex() { - return stateManager.cycleRecorder.currentCycleIndex(); - } - - protected boolean isAloneDistance() { - return stateManager.getCachedData().isAloneDistance(stateManager.getCurrentCycle(), getCurrentIndex()); - } - - protected double getInstrumentHeight() { - return stateManager.getInsturmentHeight(); - } - - protected void refreshGoBackBtnEnable() { - stateManager.refreshGoBackBtnEnable(); - } - - protected void resetLearnDataTag() { - getRequestSurveyorParamAuto().resetCodeAutoMeasureCondition(); - } - -} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructState.java new file mode 100644 index 0000000..f86f48a --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructState.java @@ -0,0 +1,349 @@ +package com.bingce.controlnetwork.surveyor.state.base; + +import android.content.Context; +import android.os.Bundle; +import android.text.TextUtils; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.fragment.TipsFragment; +import com.bingce.controlnetwork.fragment.TipsWith2OptionFragment; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyor; +import com.bingce.utils.ThreadPoolUtil; + + +public abstract class AbstructState { + + protected final StateType stateType; + protected final AbstructStateManager stateManager; + + public AbstructState(final StateType stateType, final AbstructStateManager stateManager) { + this.stateType = stateType; + this.stateManager = stateManager; + } + + protected abstract void setSurveyPosition(int notFinishPointIndex, LeftOrRight leftOrRight); + + protected abstract int getCycleCount(); + + public abstract void enter(Bundle args);//进入状态 + + protected abstract void setStationCycle(int cycle); + + protected abstract void setStationScheduleForSingleCycle(int cycleIndex, String statue); + + protected abstract void setStationScheduleForAllCycle(String statue); + + final protected StateType getType() { + return stateType; + } + + protected void setStateManagerCuttentState(StateType stateType) { + stateManager.setCurrentState(stateType); + } + + final protected @NonNull ToleranceDetailRecord getToleranceRecord() { + return stateManager.getToleranceRecord(); + } + + final protected @NonNull ISurveyorData getSurveyorData() { + return stateManager.getSurveyorData(); + } + + protected @NonNull IAutoModeSwitcher autoModeRecorder() { + return stateManager; + } + + final protected ISurveyor surveyorImpl() { + return stateManager.getSurveyor(); + } + + final protected @NonNull ICachedData getCachedData() { + return stateManager.getCachedData(); + } + + protected SurveyorStationRecord getStation() { + return stateManager.getStationRecord(); + } + + final protected @NonNull ICycleRecorder getCycleRecorder() { + return stateManager.getCycleRecorder(); + } + + final protected @NonNull Context getContext() { + return stateManager.getContext(); + } + + protected boolean isWellSteel() { + return stateManager.getCachedData().isWellSteelPoint(getCurrentCycleIndex(), getCurrentItemIndex()); + } + + protected boolean isAloneMeasureDistancePoint() { + return stateManager.getCachedData().isAloneMeasureDistancePoint(getCurrentCycleIndex(), getCurrentItemIndex()); + } + + protected void setCurrentDataCategory(DataCategory dataCategory) { + getSurveyorData().setDataCategory(dataCategory); + } + + protected DataCategory getCurrentDataCategory() { + return getSurveyorData().dataCategory(); + } + + protected LeftOrRight getCurrentLeftOrRight() { + return getSurveyorData().leftOrRight(); + } + + protected void setCurrentLeftOrRight(LeftOrRight leftOrRight) { + getSurveyorData().setLeftOrRight(leftOrRight); + } + + protected int getCurrentItemIndex() { + return getSurveyorData().currentIndex(); + } + + protected void setCurrentItemIndex(int itemIndex) { + getSurveyorData().setCurrentIndex(itemIndex); + } + + public int getCurrentCycleIndex() { + return getCycleRecorder().currentCycleIndex(); + } + + public void setCurrentCycleIndex(int cycleIndex) { + getCycleRecorder().changeCycleIndex(cycleIndex); + } + + public String getCurrentPointId() { + return getCachedData().pointId(getCurrentCycleIndex(), getCurrentItemIndex()); + } + + public boolean isStationClosed() { + return stateManager.isStationAutoClosed(); + } + + public String stationId() { + return stateManager.stationId(); + } + + public int getSurveyorCount() { + return getSurveyorData().surveyorCount(); + } + + final public FragmentManager fragmentManager() { + return stateManager.fragmentManager(); + } + + final public LifecycleOwner lifecycleOwner() { + return stateManager.lifecycleOwner(); + } + + protected int measureWhat() { + return stateManager.getMeasureWhat(); + } + + final public void scroll2(int cycleIndex, int itemIndex) { + stateManager.getScrollDelegate().onScrollTo(cycleIndex, itemIndex); + } + + final protected void toast(String warning) { + Toast.makeText(getContext(), warning, Toast.LENGTH_SHORT).show(); + } + + final protected void toast(@StringRes int warning) { + Toast.makeText(getContext(), warning, Toast.LENGTH_SHORT).show(); + } + + final protected void navigation2(StateType stateType) { + stateManager.enter(stateType); + } + + final protected void navigation2(StateType stateType, Bundle args) { + stateManager.enter(stateType, args); + } + + protected boolean isAutoSurveyOpen() { + return stateManager.isAutoModeOpen(); + } + + public boolean isAutoSurveyClosed() { + return stateManager.isAutoModeClose(); + } + + protected void changeSkip(int cycleIndex, int index) { + SurveyorStationRecord station = getStation(); + //缓存点 + getCachedData().setPointAbandon(cycleIndex, index); + //站点更新 + String pointId = getCachedData().realPointId(cycleIndex, index); + for (SurveyorPoint surveyorPoint : station.items) { + if (TextUtils.equals(pointId, surveyorPoint.getOriginalPointId())) { + surveyorPoint.setAbandon(true); + break; + } + } + //更新数据库 + ThreadPoolUtil.execute(() -> { + SurveyorDatabaseFactory.instance.getSurveyorStation().update(station); + }); + } + + /** + * 更新UI + */ + final public void refreshUI() { + runOnUI(() -> getCachedData().notifyDateChange()); + } + + final public void runOnUI(Runnable runnable) { + stateManager.runOnUI(runnable); + } + + final public void runOnBackground(Runnable runnable) { + ThreadPoolUtil.execute(runnable); + } + + protected void quite() { + } + + protected void resume() { + } + + public boolean isLive() { + return !stateManager.isDead(); + } + + public void deleteAllLearnBaseData(int measureWhatCurrent, String stationId, CallBackDeleteLearnBaseData callBack) { + stateManager.deleteAllLearnBaseData(measureWhatCurrent, stationId, callBack); + } + + public void deleteLearnBaseData(int measureWhatCurrent, String stationId, String surveyPointId, CallBackDeleteLearnBaseData callBack) { + stateManager.deleteLearnBaseData(measureWhatCurrent, stationId, surveyPointId, callBack); + } + + public void tips(String msg, Runnable runnable) { + if (stateManager.isDead()) { + return; + } + TipsFragment.noCancelAbleTips(stateManager.fragmentManager(), stateManager.lifecycleOwner(), + getContext(), + msg, + -1, + () -> { + if (runnable != null) { + runnable.run(); + } + }); + } + + public void optionTips(String msg, + String confirmButton, + String cancelButton, + Runnable confirmCallback, + Runnable cancelCallback, + Runnable ignoreCallback) { + if (stateManager.isDead()) { + return; + } + TipsWith2OptionFragment.tips( + stateManager.fragmentManager(), + stateManager.lifecycleOwner(), + confirmButton, + cancelButton, + null, + msg, + new TipsWith2OptionFragment.IOperatorCallback() { + @Override + public void onConfirm() { + if (confirmCallback == null) { + return; + } + confirmCallback.run(); + } + + @Override + public void onCancel() { + if (cancelCallback == null) { + return; + } + cancelCallback.run(); + } + + @Override + public void onIgnore() { + if (ignoreCallback == null) { + return; + } + ignoreCallback.run(); + } + + @Override + public void onOption() { + } + }); + } + + final protected void optionTipsCountDown(String msg, + String confirmButton, + String cancelButton, + Runnable confirmCallback, + Runnable cancelCallback, + Runnable ignoreCallback) { + if (stateManager.isDead()) { + return; + } + + TipsWith2OptionFragment.tipsCountDownTime( + stateManager.fragmentManager(), + stateManager.lifecycleOwner(), + confirmButton, + cancelButton, + null, + msg, + new TipsWith2OptionFragment.IOperatorCallback() { + @Override + public void onConfirm() { + if (confirmCallback == null) { + return; + } + confirmCallback.run(); + } + + @Override + public void onCancel() { + if (cancelCallback == null) { + return; + } + cancelCallback.run(); + } + + @Override + public void onIgnore() { + if (ignoreCallback == null) { + return; + } + ignoreCallback.run(); + } + + @Override + public void onOption() { + } + }); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructStateManager.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructStateManager.java new file mode 100644 index 0000000..a11e03c --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AbstructStateManager.java @@ -0,0 +1,381 @@ +package com.bingce.controlnetwork.surveyor.state.base; + +import android.content.Context; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.surveyor.test.Test; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IStationPointRecordCollect; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.AutoSurveyorMethod; +import com.bingce.controlnetwork.surveyor.state.AutoModeType; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.surveyor.IAutoSurveyor; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyor; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.surveyor.surveyor.SurveyorAutoImpl; +import com.bingce.controlnetwork.surveyor.surveyor.SurveyorMockAuto; +import com.bingce.controlnetwork.surveyor.surveyor.SurveyorSingleImpl; +import com.bingce.controlnetwork.util.StationUtilPla; +import com.bingce.coordlib.model.Coordinate; +import com.bingce.totalstation.ControlSurveyData; +import com.bingce.totalstation.ControlSurveyResult; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.HashMap; +import java.util.Map; + + +public abstract class AbstructStateManager implements IAutoModeSwitcher, ISurveyState { + + protected StateType currentStateType = StateType.idle; + protected final Map stateMap = new HashMap<>(); + + private final int measureWhat; + private final boolean supportAutoSurvey; + private SurveyorStationRecord stationRecord; + private final PointRecord stationPointRecord; + private final ToleranceDetailRecord toleranceRecord; + private final Context context; + private final IStationPointRecordCollect pointRecordCollect; + private final ISurveyorData surveyorData; + private final ICycleRecorder cycleRecorder; + private final ICachedData cachedData; + private final ISurveyorDataScrollDelegate scrollDelegate; + private final FragmentManager fragmentManager; + private final LifecycleOwner lifecycleOwner; + private final IUIRunner iuiRunner; + + private final ISurveyor surveyor; + + private AutoModeType autoMode = AutoModeType.unknown; + + //学习后用于自动测量的数据 key 点id + private final Map learnDataMap = new HashMap<>(); + + public AbstructStateManager( + final int measureWhat, + final boolean supportAutoSurvey,//是否支持自动测量 + final @NonNull SurveyorStationRecord stationRecord, + final @NonNull PointRecord stationPointRecord, + final @NonNull ToleranceDetailRecord toleranceRecord, + final @NonNull Context context, + final @NonNull IStationPointRecordCollect pointRecordCollect, + final @NonNull ISurveyorData surveyorData, + final @NonNull ICycleRecorder cycleRecorder, + final @NonNull ICachedData cachedData, + final @NonNull ISurveyorDataScrollDelegate scrollDelegate, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner iuiRunner + ) { + this.measureWhat = measureWhat; + this.supportAutoSurvey = supportAutoSurvey; + this.stationRecord = stationRecord; + this.stationPointRecord = stationPointRecord; + this.toleranceRecord = toleranceRecord; + this.context = context; + this.pointRecordCollect = pointRecordCollect; + this.surveyorData = surveyorData; + this.cycleRecorder = cycleRecorder; + this.cachedData = cachedData; + this.scrollDelegate = scrollDelegate; + this.fragmentManager = fragmentManager; + this.lifecycleOwner = lifecycleOwner; + this.iuiRunner = iuiRunner; + + if (Test.DEBUG) { + surveyor = new SurveyorMockAuto(measureWhat, stationRecord.getId(), + stationRecord.isAutoClose(), + StationUtilPla.getCycleCount(StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT, stationRecord, toleranceRecord), + cachedData, surveyorData, cycleRecorder, this, this); + } else { + if (supportAutoSurvey) { + surveyor = new SurveyorAutoImpl(measureWhat, cachedData, surveyorData, pointRecordCollect, this, + autoSurveyor, cycleRecorder); + } else { + surveyor = new SurveyorSingleImpl(measureWhat); + } + } + + initState(); + + //注册接收数据的状态 + surveyor.register(getISurveyorListener()); + surveyor.register(getISurveyorRemindListener()); + + } + + + protected abstract void initState(); + + protected abstract void refreshUiPage(); + + protected abstract ISurveyorListener getISurveyorListener(); + + protected abstract ISurveyorRemindListener getISurveyorRemindListener(); + + + public AbstructState getCurrentState() { + return stateMap.get(currentStateType); + } + + public void setCurrentState(StateType stateType) { + currentStateType = stateType; + } + + @Override + public boolean isAutoModeOpen() { + return autoMode == AutoModeType.start; + } + + @Override + public boolean isAutoModeClose() { + return autoMode == AutoModeType.stop; + } + + @Override + public boolean isAutoModeInit() { + return autoMode == AutoModeType.unknown; + } + + @Override + public void openAutoMode() { + autoMode = AutoModeType.start; + } + + @Override + public void closeAutoMode() { + autoMode = AutoModeType.stop; + } + + @Override + public void resetAutoMode() { + autoMode = AutoModeType.unknown; + } + + @Override + public void isReadyAutoSurvey(AutoSurveyorMethod.CallBackLearnResultCode callBackLearnResultCode) { + if (!supportAutoSurvey) { + callBackLearnResultCode.result(ControlSurveyResult.CODE_ERROR); + return; + } + if (!surveyor.isReady()) {//仪器连接上才算ready + callBackLearnResultCode.result(ControlSurveyResult.CODE_ERROR); + return; + } + AutoSurveyorMethod.checkAndReloadLearnData(learnDataMap, getMeasureWhat(), stationId(), cachedData, pointRecordCollect, + Double.parseDouble(stationRecord.getInstrumentHeightDeal()), stationPointRecord, + callBackLearnResultCode); + } + + @Override + public void isMeasuredValueMatchDesign(AutoSurveyorMethod.CallBackCheckDesign callBackCheckDesign) { + if (!supportAutoSurvey) { + callBackCheckDesign.result(null); + return; + } + AutoSurveyorMethod.checkDesignData(getMeasureWhat(), stationId(), cachedData, pointRecordCollect, Double.parseDouble(stationRecord.getInstrumentHeightDeal()), + stationPointRecord, callBackCheckDesign); + } + + public final boolean isStationAutoClosed() { + return stationRecord.isAutoClose(); + } + + public String stationId() { + return stationRecord.getId(); + } + + public FragmentManager fragmentManager() { + return this.fragmentManager; + } + + public LifecycleOwner lifecycleOwner() { + return this.lifecycleOwner; + } + + private final IAutoSurveyor autoSurveyor = new IAutoSurveyor() { + @Override + public Coordinate stationPoint(String originPointId) { + ControlSurveyData result = learnDataMap.get(originPointId); + return result == null ? null : result.getStation(); + } + + @Override + public double instrumentHeight() { + return Double.parseDouble(stationRecord.getInstrumentHeightDeal()); + } + + @Override + public Coordinate targetPoint(String originPointId) { + ControlSurveyData result = learnDataMap.get(originPointId); + return result == null ? null : result.getTarget(); + } + + @Override + public double angleDifference(String originPointId) { + ControlSurveyData result = learnDataMap.get(originPointId); + return result == null ? 0 : result.getAngleDifference(); + } + }; + + public void deleteAllLearnBaseData(int measureWhatCurrent, String stationId, CallBackDeleteLearnBaseData callBack) { + ThreadPoolUtil.execute(() -> { + clearLearnData(); + SurveyorDatabaseFactory.instance.getLearnDataSource().deleteByStationId(measureWhatCurrent, stationId); + callBack.next(); + }); + } + + public void deleteLearnBaseData(int measureWhatCurrent, String stationId, String surveyPointId, CallBackDeleteLearnBaseData callBack) { + ThreadPoolUtil.execute(() -> { + clearLearnData(); + SurveyorDatabaseFactory.instance.getLearnDataSource().deleteByStationPointId( + measureWhatCurrent, + stationId, surveyPointId); + ThreadPoolUtil.executeInMain(callBack::next); + }); + } + + private void clearLearnData() { + learnDataMap.clear(); + } + + public void runOnUI(Runnable action) { + if (iuiRunner != null) { + iuiRunner.runOnUI(action); + } + } + + public ICachedData getCachedData() { + return cachedData; + } + +// public void setCachedData(ICachedData cachedData) { +// this.cachedData = cachedData; +// } + + public int getMeasureWhat() { + return measureWhat; + } + + public boolean isSupportAutoSurvey() { + return supportAutoSurvey; + } + + public SurveyorStationRecord getStationRecord() { + return stationRecord; + } + + public PointRecord getStationPointRecord() { + return stationPointRecord; + } + + public ToleranceDetailRecord getToleranceRecord() { + return toleranceRecord; + } + + public Context getContext() { + return context; + } + + public IStationPointRecordCollect getPointRecordCollect() { + return pointRecordCollect; + } + + public ISurveyorData getSurveyorData() { + return surveyorData; + } + + public ICycleRecorder getCycleRecorder() { + return cycleRecorder; + } + + public ToleranceDetailRecord getTolreanceRecord() { + return toleranceRecord; + } + + public ISurveyorDataScrollDelegate getScrollDelegate() { + return scrollDelegate; + } + + public FragmentManager getFragmentManager() { + return fragmentManager; + } + + public LifecycleOwner getLifecycleOwner() { + return lifecycleOwner; + } + + public ISurveyor getSurveyor() { + return surveyor; + } + + /** + * 获取当前测回 + * + * @return + */ + public int getCurrentCycle() { + return cycleRecorder.currentCycleIndex(); + } + + public String getProjectType() { + return stationRecord.getProjectType(); + } + + public void enter(StateType type, Bundle args) { + if (isDead()) { + return; + } + AbstructState baseState = stateMap.get(type); + currentStateType = type; + if (baseState != null) { + runOnUI(() -> baseState.enter(args)); + } + } + + public void enter(StateType type) { + enter(type, null); + } + + + public void quite() { + _live = false; + for (Map.Entry entry : stateMap.entrySet()) { + entry.getValue().quite(); + } + //进入idle状态 + currentStateType = StateType.idle; + } + + private boolean _live = true; + + public boolean isDead() { + return !_live; + } + + public void resume() { + _live = true; + for (Map.Entry entry : stateMap.entrySet()) { + entry.getValue().resume(); + } + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AdjustmentMeasureWhatUtil.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AdjustmentMeasureWhatUtil.java new file mode 100644 index 0000000..adb0f17 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/AdjustmentMeasureWhatUtil.java @@ -0,0 +1,25 @@ +package com.bingce.controlnetwork.surveyor.state.base; + + +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; + +public class AdjustmentMeasureWhatUtil { + + public static boolean isAdjustHorAngle(int measureWhat) { + return measureWhat == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR; + } + + public static boolean isAdjustVerAngle(int measureWhat) { + return measureWhat == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER; + } + + public static boolean isAdjustDistance(int measureWhat) { + return measureWhat == StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE; + } + + public static boolean isAdjustAll(int measureWhat) { + return measureWhat == StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT; +// || measureWhat == StateConstants.VALUE_MEASURE_WHAT_ANGLE; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CallBackDeleteLearnBaseData.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CallBackDeleteLearnBaseData.java new file mode 100644 index 0000000..e31d2cf --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CallBackDeleteLearnBaseData.java @@ -0,0 +1,5 @@ +package com.bingce.controlnetwork.surveyor.state.base; + +public interface CallBackDeleteLearnBaseData { + void next(); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CheckToleranceUtil.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CheckToleranceUtil.java new file mode 100644 index 0000000..a85248c --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/base/CheckToleranceUtil.java @@ -0,0 +1,51 @@ +package com.bingce.controlnetwork.surveyor.state.base; + + +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; + +public class CheckToleranceUtil { + + public static boolean checkAngleHor(int measuresWhat) { + return measuresWhat == StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT +// || measuresWhat == StateConstants.VALUE_MEASURE_WHAT_ANGLE + || measuresWhat == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR; + } + + public static boolean checkAngleVer(int measuresWhat) { + return measuresWhat == StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT +// || measuresWhat == StateConstants.VALUE_MEASURE_WHAT_ANGLE + || measuresWhat == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER; + } + + public static boolean checkDistance(int measuresWhat) { + return measuresWhat == StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT + || measuresWhat == StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE; + } + + /** + * 是否是忽略检测垂直角的点 + * + * @return + */ + public static boolean isIgnoreVerPoint(ICachedData cachedData, int cycleIndex, int pointIndex) { + boolean abondon = cachedData.isAbandonPoint(cycleIndex, pointIndex); + boolean wellSteel = cachedData.isWellSteelPoint(cycleIndex, pointIndex); + boolean measureVerNot = cachedData.getSurveyorPoint(cycleIndex, pointIndex).isMeasureVerNot(); + return abondon || wellSteel || measureVerNot; + } + + /** + * 是否是忽略检测距离的点 + * + * @return + */ + public static boolean isIgnoreDistancePoint(ICachedData cachedData, int cycleIndex, int pointIndex) { + boolean abondon = cachedData.isAbandonPoint(cycleIndex, pointIndex); + boolean wellSteel = cachedData.isWellSteelPoint(cycleIndex, pointIndex); + boolean measureVerNot = cachedData.getSurveyorPoint(cycleIndex, pointIndex).isMeasureDistanceNot(); + return abondon || wellSteel || measureVerNot; + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/StateManagerHeightTraverse.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/StateManagerHeightTraverse.java index 4704a51..1713f55 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/StateManagerHeightTraverse.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/StateManagerHeightTraverse.java @@ -140,7 +140,7 @@ public class StateManagerHeightTraverse implements IAutoModeSwitcher, ISurveySta stateMap.put(StateType.init, new _Init(positionFragment, this)); stateMap.put(StateType.doSurveyor, doSurveyorState); stateMap.put(StateType.doAutoSurveyor, new _DoAutoSurveyorState(positionFragment, this, this)); - stateMap.put(StateType.SurveyorFailure, new _SurveyorFailureState(positionFragment, this)); +// stateMap.put(StateType.SurveyorFailure, new _SurveyorFailureState(positionFragment, this)); stateMap.put(StateType.doMove2NextValidate, new _DoMove2NextValidateState(positionFragment, this)); stateMap.put(StateType.doMoveBack, new _DoMoveBackState(positionFragment, this)); stateMap.put(StateType.checkStation, new _CheckStationState(positionFragment, this)); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_DoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_DoSurveyorState.java index 0f1deee..e3c653f 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_DoSurveyorState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_DoSurveyorState.java @@ -19,6 +19,7 @@ import com.bingce.controlapphelper.util.DebugMsgUtil; import com.bingce.controlapphelper.util.Tools; import com.bingce.controlnetwork.R; import com.bingce.controlnetwork.surveyor.state.StateConstants; +import com.bingce.controlnetwork.surveyor.state._SurveyorFailureState; import com.bingce.device.Device; import com.bingce.totalstation.TotalStation; import com.bingce.totalstation.protocol.south.SouthAndroidBtInterface; diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/StateManagerSeparateVerAngle.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/StateManagerSeparateVerAngle.java new file mode 100644 index 0000000..314a502 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/StateManagerSeparateVerAngle.java @@ -0,0 +1,259 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle; + +import android.content.Context; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.fragment.StationDataAdjustAloneVerOrDistanceDialogFragment; +import com.bingce.controlnetwork.model.AloneAdjustItem; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IStationPointRecordCollect; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.SurveyorAdjustMethodTj; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.state.base.AbstructStateManager; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.util.SupportAutoSurveyorUtil; +import com.bingce.totalstation.ControlSurveyResult; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.List; + +import blankj.utilcode.util.ToastUtils; + +public class StateManagerSeparateVerAngle extends AbstructStateManager { + + private final VerAngleCheckTolerance verAngleCheckTolerance = new VerAngleCheckTolerance(); + + @WorkerThread + public static StateManagerSeparateVerAngle newInstance(int measureWhat,//仅测量水平角还是什么... + @NonNull SurveyorStationRecord stationRecord, + @NonNull Context context, + @NonNull FragmentManager fragmentManager, + @NonNull LifecycleOwner lifecycleOwner, + @NonNull ToleranceDetailRecord toleranceRecord, + @NonNull IStationPointRecordCollect pointRecordCollect, + @NonNull ISurveyorData surveyorData, + @NonNull ICycleRecorder cycleRecorder, + @NonNull ICachedData cachedData, + ISurveyorDataScrollDelegate scrollDelegate, + IUIRunner runner) { + //读取测点record + String stationPointId = null; + if (stationRecord.getItems() != null) { + for (SurveyorPoint stationItem : stationRecord.getItems()) { + if (SurveyorPoint.TYPE_STATION.equals(stationItem.getType())) { + stationPointId = stationItem.getPointId(); + break; + } + } + } + PointRecord stationPointRecord = null; + if (stationPointId != null) { + stationPointRecord = SurveyorDatabaseFactory + .instance + .getPointDataSource() + .findByIdSync(stationPointId); + } + if (stationPointRecord == null) { + return null; + } + + boolean supportAuto = SupportAutoSurveyorUtil.isSupportAuto(); + + return new StateManagerSeparateVerAngle(measureWhat, supportAuto, + stationRecord, + stationPointRecord, + toleranceRecord, + context, + pointRecordCollect, + surveyorData, + cycleRecorder, + cachedData, + scrollDelegate, + fragmentManager, lifecycleOwner, runner); + } + + + public StateManagerSeparateVerAngle(int measureWhat, boolean supportAutoSurvey, @NonNull SurveyorStationRecord stationRecord, @NonNull PointRecord stationPointRecord, @NonNull ToleranceDetailRecord toleranceRecord, @NonNull Context context, @NonNull IStationPointRecordCollect pointRecordCollect, @NonNull ISurveyorData surveyorData, @NonNull ICycleRecorder cycleRecorder, @NonNull ICachedData cachedData, @NonNull ISurveyorDataScrollDelegate scrollDelegate, FragmentManager fragmentManager, LifecycleOwner lifecycleOwner, IUIRunner iuiRunner) { + super(measureWhat, supportAutoSurvey, stationRecord, stationPointRecord, toleranceRecord, context, pointRecordCollect, surveyorData, cycleRecorder, cachedData, scrollDelegate, fragmentManager, lifecycleOwner, iuiRunner); + } + + @Override + public boolean isSurveying() { + return currentStateType == StateType.doSurveyor || currentStateType == StateType.doAutoSurveyor; + } + + @Override + public boolean isAutoSurveying() { + return isAutoModeOpen(); + } + + @Override + protected void initState() { + _DoSurveyorStateVer doSurveyorState = new _DoSurveyorStateVer(this, this); + stateMap.put(StateType.idle, new _IdleStateVer(this, this)); + stateMap.put(StateType.doSurveyor, doSurveyorState); + stateMap.put(StateType.doAutoSurveyor, new _DoAutoSurveyorState(this, this)); + stateMap.put(StateType.SurveyorFailure, new _SurveyorFailureStateVer(this)); + } + + @Override + protected void refreshUiPage() { + //暂无使用 + } + + @Override + protected ISurveyorListener getISurveyorListener() { + return (_DoSurveyorStateVer) stateMap.get(StateType.doSurveyor); + } + + @Override + protected ISurveyorRemindListener getISurveyorRemindListener() { + return (_DoSurveyorStateVer) stateMap.get(StateType.doSurveyor); + } + + public VerAngleCheckTolerance getVerAngleCheckTolerance() { + return verAngleCheckTolerance; + } + + public void doSurveyor() { + if (currentStateType == StateType.doSurveyor || currentStateType == StateType.SurveyorFailure) { + return; + } + if (Tools.isDeviceConnectedNot()) { + return; + } + startSurveyor(); + } + + public void setSurveyorData(VerAngleFindIndexUtil.VerFindTarget target, boolean isClearSurveyorState) { + getSurveyorData().setCurrentIndex(target.getPointIndex()); + getSurveyorData().setLeftOrRight(target.getLeftOrRight()); + getCycleRecorder().changeCycleIndex(target.getCycleIndex()); + if (isClearSurveyorState) { + getSurveyorData().clearSurveyState(); + } + } + + public int getCycleCount() { + // TODO: 2024/8/30 + return getToleranceRecord().getCycleCount(); + } + + public void stationAdjust() { + boolean allPointMeasured = VerAngleCheckTolerance.isAllPointMeasured(stationId(), getCachedData(), getCycleCount()); + if (!allPointMeasured) { + ToastUtils.showShort("数据不完整,请完成测量"); + return; + } + verAngleCheckTolerance.checkTolerance(getMeasureWhat(), stationId(), getCachedData(), getSurveyorData(), + getToleranceRecord(), (code, msg) -> { + if (code == VerAngleCheckTolerance.CODE_SUCCESS) { + startAdjust(); + } else { + __BaseStateVer currentState = (__BaseStateVer) getCurrentState(); + currentState.dealCheckToleranceResult(code, msg); + } + }); + } + + private void startAdjust() { + ThreadPoolUtil.execute(() -> { + List adjustItems = SurveyorAdjustMethodTj.calAloneVer(stationId(), getCachedData(), true); + StationDataAdjustAloneVerOrDistanceDialogFragment.showDialog(getFragmentManager(), getMeasureWhat(), adjustItems); + }); + } + + public void startRollBack() { + //找到回退的数据 + VerAngleFindIndexUtil.VerFindTarget rollBackTarget = VerAngleFindIndexUtil.findTargetFromSurveyorData(getSurveyorData(), getCycleRecorder()); + if (rollBackTarget == null) { + rollBackTarget = VerAngleFindIndexUtil.findRollBackTarget(stationId(), getCachedData(), + getSurveyorData().currentIndex(), getCycleCount()); + if (rollBackTarget.getCycleIndex() == -1) { + ToastUtils.showShort("没有可以回退的数据"); + return; + } + } + + __BaseStateVer currentState = (__BaseStateVer) getCurrentState(); + currentState.showRollBackDialog(rollBackTarget); + } + + /** + * 删除当前点下的当前测回记录 + */ + public void deleteCurrentCycleData() { + //找到数据 + VerAngleFindIndexUtil.VerFindTarget rollBackTarget = VerAngleFindIndexUtil.findTargetFromSurveyorData(getSurveyorData(), getCycleRecorder()); +// if (rollBackTarget == null) { +// rollBackTarget = VerAngleFindIndexUtil.findRollBackTarget(stationId(), getCachedData(), +// getSurveyorData().currentIndex(), getCycleCount()); +// if (rollBackTarget.getCycleIndex() == -1) { +// return; +// } +// } + + __BaseStateVer currentState = (__BaseStateVer) getCurrentState(); + currentState.startDeleteOneCycleData(rollBackTarget); + } + + /** + * 删除当前点下的当前测回记录 + */ + public void deletePointAllCycleData() { + if (!VerDeleteDataUtil.isHasData(getSurveyorData(), getCachedData(), getCycleCount())) { + ToastUtils.showShort("没有数据了"); + return; + } + __BaseStateVer currentState = (__BaseStateVer) getCurrentState(); + currentState.showPointAllCycleDialog(); + } + + public void startSurveyor() { + int cycleIndex = getCycleRecorder().currentCycleIndex(); + LeftOrRight leftOrRight = getSurveyorData().leftOrRight(); + int measureTimes = getSurveyorData().getMeasureTimes(); + if (isAutoModeInit() && cycleIndex == 0 && measureTimes == 0 && leftOrRight == LeftOrRight.left) { + //自动测量初始化状态且第一测回的盘左 + isReadyAutoSurvey(isReadyCode -> { + boolean isReady = isReadyCode == ControlSurveyResult.CODE_SUCCESS; + if (isReady) { + __BaseStateVer currentState = (__BaseStateVer) getCurrentState(); + currentState.tips4StartAutoSurvey(this); + } else { + enterDoSurveyor(); + } + }); + } else { + enterDoSurveyor(); + } + } + + private void enterDoSurveyor() { + Bundle bundle = new Bundle(); + if (StateType.doWellMeasureRotationReady == currentStateType) { + //当前是钢丝准备状态 + //传给测量状态isAlreadyRemindUserAimingAtWire + bundle.putBoolean(StateConstantsTj.KEY_IS_ALREADY_REMIND_USER_AIMING_AT_WIRE, true); + } + enter(StateType.doSurveyor, bundle); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckReadUtil.kt b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckReadUtil.kt new file mode 100644 index 0000000..d4a484d --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckReadUtil.kt @@ -0,0 +1,26 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle + +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord +import com.bingce.controlapphelper.surveyor.method.DeviationValueOfRadianMethod +import com.bingce.controlapphelper.surveyor.method.RadianMethod +import com.bingce.controlnetwork.surveyor.data.ISurveyorData + + +object VerAngleCheckReadUtil { + + fun checkRead(surveyorData: ISurveyorData, toleranceDetail: ToleranceDetailRecord): String? { + val surveyorCount: Int = toleranceDetail.getSurveyorCount() + if (surveyorCount > 1) { + val verDifference: Double = toleranceDetail.getVerReadDifference() + val verDiffRadian = DeviationValueOfRadianMethod.similarRadianDiff( + surveyorData.angleVer1, + surveyorData.angleVer2 + ) + if (verDifference < RadianMethod.radian2S(verDiffRadian)) { + return "垂直角读数超限,请重新观测该目标." + } + } + return null + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckTolerance.kt b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckTolerance.kt new file mode 100644 index 0000000..89fca02 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleCheckTolerance.kt @@ -0,0 +1,419 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle + +import android.text.TextUtils + + +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord +import com.bingce.controlapphelper.model.DataCategory +import com.bingce.controlapphelper.model.LeftOrRight +import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType +import com.bingce.controlnetwork.surveyor.data.ICachedData +import com.bingce.controlnetwork.surveyor.data.ISurveyorData +import com.bingce.controlnetwork.surveyor.method.ValueOf2cMethod +import com.bingce.controlnetwork.util.IdUtil + +import com.bingce.utils.Util +import kotlin.math.abs + +class VerAngleCheckTolerance { + + private var msg: String? = null + private var code = CODE_SUCCESS + + companion object { + const val CODE_SUCCESS = 0 //没问题 + const val CODE_ERROR_TIPS = 1 //错误提示 + const val CODE_ERROR_NEED_REMEASURE = 2 //错误需要重测 + + @JvmStatic + fun isAllPointMeasured( + stationId: String, + cachedData: ICachedData, + cycleCount: Int + ): Boolean { + for (pointIndex in 0 until cachedData.realPointCount()) { + for (cycleIndex in 0 until cycleCount) { + val pointId = cachedData.pointId(cycleIndex, pointIndex) + + val leftKey = + IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left) + val rightKey = + IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right) + + val leftDataCategory = cachedData.valueState(leftKey) + val rightDataCategory = cachedData.valueState(rightKey) + + if (!leftDataCategory.isFreshData || !rightDataCategory.isFreshData) { + return false + } + } + } + return true + } + } + + /** + * 1.每次在点击开始测量按钮时出发检查限差 + * 2.获取到数据后检测限差 + */ + fun checkToleranceAndSave( + measureWhat: Int, + stationId: String, + cachedData: ICachedData, + surveyorData: ISurveyorData, + surveyorCycleIndex: Int, + toleranceDetail: ToleranceDetailRecord, + callBack: IVerAngleCheckToleranceCallBack, + ) { + val errorMsg = VerAngleCheckReadUtil.checkRead(surveyorData, toleranceDetail) + if (!TextUtils.isEmpty(errorMsg)) { + backData(CODE_ERROR_TIPS, errorMsg, callBack) + return + } + + //存数据到cacheData + saveCacheData( + measureWhat, + cachedData, + surveyorData, + surveyorCycleIndex, + object : ICachedData.CallBackCache { + override fun success() { + startCheckOtherTolerance( + measureWhat, + stationId, + cachedData, + surveyorData, + surveyorCycleIndex, + toleranceDetail, + callBack + ) + } + + override fun failure() { + backData(CODE_ERROR_TIPS, "存储数据异常", callBack) + } + }) + + } + + /** + * 1.每次在点击开始测量按钮时出发检查限差 + * 2.获取到数据后检测限差 + */ + fun checkTolerance( + measureWhat: Int, + stationId: String, + cachedData: ICachedData, + surveyorData: ISurveyorData, + toleranceDetail: ToleranceDetailRecord, + callBack: IVerAngleCheckToleranceCallBack, + ) { + //所有测回测点都测量完成检测测回间限差 + checkStationToleranceError( + measureWhat, + stationId, + cachedData, + surveyorData, + toleranceDetail, + callBack + ) + } + + private fun startCheckOtherTolerance( + measureWhat: Int, + stationId: String, + cachedData: ICachedData, + surveyorData: ISurveyorData, + cycleIndex: Int, + toleranceDetail: ToleranceDetailRecord, + callBack: IVerAngleCheckToleranceCallBack + ) { + //检测i + val value2C = ValueOf2cMethod.valueOf2C( + SdAngleValueType.verAngle, + stationId, + cycleIndex, + surveyorData.currentIndex(), + surveyorData, + cycleIndex, + cachedData + ) + + if (value2C.validate && toleranceDetail.getVerI() < abs(value2C.value)) { + val stringBuilder = StringBuilder() + stringBuilder.append("竖直角i指标超限(限差:") + .append(toleranceDetail.getVerI()) + .append("'')\n") + .append(" 测量值:") + .append(Util.formatDouble2String(abs(value2C.value), 1)) + .append("''") + backData(CODE_ERROR_NEED_REMEASURE, stringBuilder.toString(), callBack) + return + } + + // TODO: + val cycleCount = toleranceDetail.getCycleCount() + //检测所有数据是否测量完成 + val allPointMeasured = isAllPointMeasured(stationId, cachedData, cycleCount) + if (!allPointMeasured) { + backData(CODE_SUCCESS, null, callBack) + return + } + + //所有测回测点都测量完成检测测回间限差 + checkStationToleranceError( + measureWhat, + stationId, + cachedData, + surveyorData, + toleranceDetail, + callBack + ) + } + + private fun checkStationToleranceError( + measureWhat: Int, + stationId: String, + cachedData: ICachedData, + surveyorData: ISurveyorData, + toleranceDetail: ToleranceDetailRecord, + callBack: IVerAngleCheckToleranceCallBack + ) { + // TODO: +// val cycleCount = toleranceDetail.cycleCount +// val surveyorCount = surveyorData.surveyorCount() +// +// //*****测回间垂直角互差(垂直角) +// val verCyclesAngleDifference: Double = +// toleranceDetail.getVerCyclesAngleDifference() /*verCyclesAngleDifference*/ +// +// val verValueErrorList = mutableListOf() +// +// //执行计算 +// for (cycleI in 0 until cycleCount) { +// +// +// val valuesI = +// DeviationValueOfRadianMethod.zeroValueOfSingleCycleInLeftOrientation( +// measureWhat, +// stationId, +// cycleI, +// surveyorCount, +// cachedData +// ) +// +// if (valuesI.isEmpty()) { +// backData(CODE_ERROR_TIPS, "第" + (cycleI + 1) + "测回,数据不完整!", callBack) +// return +// } +// +// for (cycleJ in cycleI + 1 until cycleCount) { +// val valuesJ = +// DeviationValueOfRadianMethod.zeroValueOfSingleCycleInLeftOrientation( +// measureWhat, +// stationId, +// cycleJ, +// surveyorCount, +// cachedData +// ) +// if (valuesI.size != valuesJ.size) { +// backData(CODE_ERROR_TIPS, "第" + (cycleJ + 1) + "测回,数据不完整!", callBack) +// return +// } +// +// val size = valuesI.size +// for (index in 0 until size) { +// val diff = abs( +// DeviationValueOfRadianMethod +// .similarRadianDiff( +// valuesI[index].verRadian, valuesJ[index].verRadian +// ) +// ) +// if (verCyclesAngleDifference < RadianMethod.radian2S(diff)) { +// verValueErrorList.add( +// StationCheckErrorItem( +// valuesI[index].pointName, +// cycleI, cycleJ, RadianMethod.radian2S(diff) +// ) +// ) +// } +// } +// } +// } +// +// +// //*****测回间垂直角I互差(垂直角) +// val verCyclesIDifference = +// toleranceDetail.getVerCyclesIDifference() /*verCyclesIDifference*/ +// val verIErrorList = mutableListOf() +// +// val pointArrayList = mutableListOf() +// +// //遍历第一测回,收集所有待测点id +// for (index in 0 until cachedData.realPointCount()) { +// if (cachedData.isAbandonPoint(0, index)) { +// continue +// } +// pointArrayList.add( +// StationCheckErrorPoint( +// cachedData.pointId(0, index), +// cachedData.pointName(0, index) +// ) +// ) +// } +// +// //检测所有待测点i互差 +// for (point in pointArrayList) { +// for (cycleI in 0 until cycleCount) { +// val leftRecordId_I = +// IdUtil.surveyorRecordKey(stationId, cycleI, point.pointId, LeftOrRight.left) +// val rightRecordId_I = +// IdUtil.surveyorRecordKey(stationId, cycleI, point.pointId, LeftOrRight.right) +// val value2C_I = ValueOf2cMethod.valueOf2C( +// SdAngleValueType.verAngle, leftRecordId_I, rightRecordId_I, +// toleranceDetail.getSurveyorCount(), cachedData +// ) +// +// for (cycleJ in cycleI + 1 until cycleCount) { +// val leftRecordId_J = +// IdUtil.surveyorRecordKey(stationId, cycleJ, point.pointId, LeftOrRight.left) +// val rightRecordId_J = IdUtil.surveyorRecordKey( +// stationId, +// cycleJ, +// point.pointId, +// LeftOrRight.right +// ) +// val value2C_J = ValueOf2cMethod.valueOf2C( +// SdAngleValueType.verAngle, leftRecordId_J, rightRecordId_J, +// toleranceDetail.getSurveyorCount(), cachedData +// ) +// +// val verI = abs(value2C_I.value - value2C_J.value) +// if (verCyclesIDifference < verI) { +// verIErrorList.add( +// StationCheckErrorItem( +// point.pointName, +// cycleI, +// cycleJ, +// verI +// ) +// ) +// } +// +// } +// } +// } +// +// val errorString = errorString( +// verCyclesAngleDifference, +// verCyclesIDifference, +// verValueErrorList, +// verIErrorList +// ) +// +// if (errorString != null) { +// backData(CODE_ERROR_NEED_REMEASURE, errorString, callBack) +// return +// } + backData(CODE_SUCCESS, null, callBack) + } + + private fun backData(code: Int, errorMsg: String?, callBack: IVerAngleCheckToleranceCallBack) { + callBack.back(code, errorMsg) + this.code = code + this.msg = errorMsg + } + + private fun saveCacheData( + measureWhat: Int, + cachedData: ICachedData, + surveyorData: ISurveyorData, + cycleIndex: Int, + callBack: ICachedData.CallBackCache + ) { + //设置数据正常 + surveyorData.setDataCategory(DataCategory.normalCategory()) + + //存储(缓存+数据库) + cachedData.cache( + measureWhat, + cycleIndex, + surveyorData, + callBack + ) + } + + fun getCode() = code + fun getMsg() = msg + + fun isToleranceError() = code != CODE_SUCCESS + + fun resetCodeMsg() { + code = CODE_SUCCESS + msg = null + } + + + interface IVerAngleCheckToleranceCallBack { + fun back(code: Int, msg: String?) + } + + +// /** +// * 根据超限信息生成错误描述 +// */ +// private fun errorString( +// verLimit: Double, +// verILimit: Double, +// verValueError: List, +// verIError: List +// ): String? { +// val stringBuilder = StringBuilder() +// +// if (verValueError.isNotEmpty()) { +// stringBuilder.append("测回间垂直角互差超限(限差:") +// .append(Util.formatDouble2String(verLimit, 1)) +// .append("'')") +// for (item in verValueError) { +// stringBuilder +// .append("\n ") +// .append(item.pointName) +// .append(":\n") +// .append(" |") +// .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) +// .append("-") +// .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) +// .append("| = ") +// .append(Util.formatDouble2String(item.difference, 1)) +// .append("'')") +// } +// } +// +// if (verIError.isNotEmpty()) { +// stringBuilder.append("\n垂直角i指标同方向各测回较差超限(限差:") +// .append(Util.formatDouble2String(verILimit, 1)) +// .append("'')") +// for (item in verIError) { +// stringBuilder +// .append("\n ") +// .append(item.pointName) +// .append(":\n") +// .append(" |") +// .append(SurveyorCycleUtil.cycleName(item.cycleIndex1)) +// .append("-") +// .append(SurveyorCycleUtil.cycleName(item.cycleIndex2)) +// .append("| = ") +// .append(Util.formatDouble2String(item.difference, 1)) +// .append("'')") +// } +// } +// +// if (stringBuilder.isNotEmpty()) { +// return stringBuilder.toString() +// } +// return null +// } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleFindIndexUtil.kt b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleFindIndexUtil.kt new file mode 100644 index 0000000..bcf61ad --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerAngleFindIndexUtil.kt @@ -0,0 +1,123 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle + +import com.bingce.controlapphelper.model.LeftOrRight +import com.bingce.controlnetwork.surveyor.data.ICachedData +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder +import com.bingce.controlnetwork.surveyor.data.ISurveyorData +import com.bingce.controlnetwork.util.IdUtil + +/** + * 查询当前要测的点的index + */ +object VerAngleFindIndexUtil { + + @JvmStatic + fun getTargetByPointIndexFront( + stationId: String, + cachedData: ICachedData, + currentPointIndex: Int, + cycleCount: Int + ): VerFindTarget { + val pointId = cachedData.pointId(0, currentPointIndex) + + for (cycleIndex in 0 until cycleCount) { + val leftKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left) + val rightKey = + IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right) + + val leftDataCategory = cachedData.valueState(leftKey) + val rightDataCategory = cachedData.valueState(rightKey) + + if (leftDataCategory.isNeedResurvey || leftDataCategory.isEmptyData) { + return VerFindTarget(cycleIndex, currentPointIndex, LeftOrRight.left) + } + + if (rightDataCategory.isNeedResurvey || rightDataCategory.isEmptyData) { + return VerFindTarget(cycleIndex, currentPointIndex, LeftOrRight.right) + } + } + return VerFindTarget(-1, currentPointIndex, LeftOrRight.left) + } + + @JvmStatic + private fun getRollBackTarget( + stationId: String, + cachedData: ICachedData, + currentPointIndex: Int, + cycleCount: Int + ): VerFindTarget { + val pointId = cachedData.pointId(0, currentPointIndex) + + for (cycleIndex in cycleCount - 1 downTo 0) { + val leftKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left) + val rightKey = + IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.right) + + val leftDataCategory = cachedData.valueState(leftKey) + val rightDataCategory = cachedData.valueState(rightKey) + if (rightDataCategory.isFreshData) { + return VerFindTarget(cycleIndex, currentPointIndex, LeftOrRight.right) + } + if (leftDataCategory.isFreshData) { + return VerFindTarget(cycleIndex, currentPointIndex, LeftOrRight.left) + } + } + return VerFindTarget(-1, currentPointIndex, LeftOrRight.left) + } + + @JvmStatic + fun findFront( + stationId: String, + cachedData: ICachedData, + currentPointIndex: Int, + cycleCount: Int + ): VerFindTarget { + for (pointIndex in currentPointIndex until cachedData.realPointCount()) { + val target = + getTargetByPointIndexFront(stationId, cachedData, pointIndex, cycleCount) + if (target.cycleIndex != -1) { + return target + } + } + return VerFindTarget(-1, cachedData.realPointCount() - 1, LeftOrRight.right) + } + + @JvmStatic + fun findRollBackTarget( + stationId: String, + cachedData: ICachedData, + currentPointIndex: Int, + cycleCount: Int + ): VerFindTarget { + for (pointIndex in currentPointIndex downTo 0) { + val target = + getRollBackTarget(stationId, cachedData, pointIndex, cycleCount) + if (target.cycleIndex != -1) { + return target + } + } + return VerFindTarget(-1, currentPointIndex, LeftOrRight.left) + } + + @JvmStatic + fun findTargetFromSurveyorData( + surveyorData: ISurveyorData, + cycleRecorder: ICycleRecorder + ): VerFindTarget? { + //找到回退的数据 + val hasData = surveyorData.hasSurveyor1() + if (hasData) { + return VerFindTarget( + cycleRecorder.currentCycleIndex(), + surveyorData.currentIndex(), + surveyorData.leftOrRight() + ) + } + return null + } + + + data class VerFindTarget(val cycleIndex: Int, val pointIndex: Int, val leftOrRight: LeftOrRight) + + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerDeleteDataUtil.kt b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerDeleteDataUtil.kt new file mode 100644 index 0000000..862fa97 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/VerDeleteDataUtil.kt @@ -0,0 +1,24 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle + +import com.bingce.controlapphelper.model.LeftOrRight +import com.bingce.controlnetwork.surveyor.data.ICachedData +import com.bingce.controlnetwork.surveyor.data.ISurveyorData + + +object VerDeleteDataUtil { + + @JvmStatic + fun isHasData(surveyorData: ISurveyorData, cachedData: ICachedData, cycleCount: Int): Boolean { + for (cycleIndex in 0 until cycleCount) { + val hasDataLeft = + cachedData.isHasData(cycleIndex, surveyorData.currentIndex(), LeftOrRight.left) + val hasDataRight = + cachedData.isHasData(cycleIndex, surveyorData.currentIndex(), LeftOrRight.right) + if (hasDataLeft || hasDataRight) { + return true + } + } + return false + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoAutoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoAutoSurveyorState.java new file mode 100644 index 0000000..da779a3 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoAutoSurveyorState.java @@ -0,0 +1,33 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle; + +import android.os.Bundle; + +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.totalstation.ControlSurveyResult; + +import net.tatans.tensorflowtts.tts.TtsManager; + + +/** + * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 + */ +class _DoAutoSurveyorState extends __BaseStateVer { + private final IAutoModeSwitcher autoModeSwitcher; + + public _DoAutoSurveyorState(StateManagerSeparateVerAngle stateManager, IAutoModeSwitcher autoModeSwitcher) { + super(StateType.doAutoSurveyor, stateManager); + this.autoModeSwitcher = autoModeSwitcher; + } + + @Override + public void enter(Bundle args) { + autoModeSwitcher.isReadyAutoSurvey(code -> { + if (code==ControlSurveyResult.CODE_SUCCESS) { + autoModeSwitcher.openAutoMode(); + navigation2(StateType.doMove2NextValidate); + TtsManager.getInstance().speak("开始自动测量"); + } + }); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoSurveyorStateVer.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoSurveyorStateVer.java new file mode 100644 index 0000000..304b21d --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_DoSurveyorStateVer.java @@ -0,0 +1,211 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.widget.Toast; + +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.surveyor.surveyor.RequestParam; +import com.bingce.device.Device; +import com.bingce.totalstation.TotalStation; +import com.bingce.totalstation.protocol.topcon.TopconInterface; + +import net.tatans.tensorflowtts.tts.TtsManager; + + +/** + * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 + */ +class _DoSurveyorStateVer extends __BaseStateVer implements ISurveyorListener, ISurveyorRemindListener { + private final ISurveyState surveyState; + //最多测量次数,如果5次测量都没有获取正常数据,则跳过 + private static final int MAX_SURVEYOR_COUNT = 3; + private static int failureCount = 0; + private static final int RESULT_SUCCESS = 0; + private static final int RESULT_FAILURE_EXCEED_MAX = 1;//测量失败次数超出最大限制 key + private static final int RESULT_FAILURE_ERROR = 2;//测量失败,又没有允许重复尝试 key + private static final boolean allowTryWhenFailure = true;//在测量失败的时候,是否允许重新测量 + + private int surveyorIndex = 0; + private boolean isAlreadyRemindUserAimingAtWire = false; + + private Handler handler; + + public _DoSurveyorStateVer(StateManagerSeparateVerAngle stateManager, ISurveyState surveyState) { + super(StateType.doSurveyor, stateManager); + this.surveyState = surveyState; + handler = new Handler(Looper.getMainLooper()); + } + + @Override + public void enter(Bundle args) { + surveyorIndex = 0; + getSurveyorData().setMeasureTimes(0); + isAlreadyRemindUserAimingAtWire = false; + if (args != null) { + isAlreadyRemindUserAimingAtWire = args.getBoolean(StateConstantsTj.KEY_IS_ALREADY_REMIND_USER_AIMING_AT_WIRE); + } + + //3.其他测回没有正在测量数据,则在当前测回执行测量 + doSurveyor(); + } + + private void doSurveyor() { + failureCount = 0; + //判断设备是否连接 + if (surveyorImpl().isReady()) { + //发送测量信号 + SurveyStateEvent.postSurveying(); + //注册接收测量数据 + surveyorImpl().prepareSurveyor(); + sendSurveyRequest(); + } else { + recoverIdleSurveyorState(getSurveyorData(), getCycleRecorder()); + Device.getInstance().remindConnectDevice(); + } + } + + private void sendSurveyRequestNext() { + if (isAutoSurveyOpen()) { + refreshUI(); + //当自动测量的时候继续发送测量指令 + sendSurveyRequestNextInner(); + } else { + //进入idle + recoverIdleSurveyorState(getSurveyorData(), getCycleRecorder()); + } + } + + private void sendSurveyRequestNextInner() { + if (TotalStation.getInstance() instanceof TopconInterface) { + //这个仪器需要延迟500毫秒发送指令 + handler.postDelayed(this::sendSurveyRequest, 500); + } else { + sendSurveyRequest(); + } + } + + private void sendSurveyRequest() { + int surveyorPointIndex = getCurrentItemIndex(); + if (surveyorPointIndex < 0) { + surveyorPointIndex = 0; + } + SurveyorPoint surveyorPoint = getCachedData().getSurveyorPoint(getCycleRecorder().currentCycleIndex(), surveyorPointIndex); + surveyorImpl().requestSurveyor(new RequestParam(measureWhat(), isAlreadyRemindUserAimingAtWire, isWellSteel(), isAloneMeasureDistancePoint(), surveyorIndex, surveyorPointIndex, surveyorPoint)); + } + + private void onSuccess() { + onCompleted(RESULT_SUCCESS, ""); + } + + private void onCompleted(int result, String msg) { + //退出测量 + surveyorImpl().exitSurveyor(); + switch (result) { + case RESULT_SUCCESS://进入读数检测状态 + //检测是否处于「自动测量」 + if (!surveyState.isAutoSurveying()) { + SurveyStateEvent.postSuccess(); + } + //进入到这里肯定是测量完成了,单次或两次测量完成 + startCheckTolerance(); + break; + case RESULT_FAILURE_EXCEED_MAX: +// boolean allowAbandon = App.getApp().isAllowSkip; + dealErrorDataNormal(msg); + break; + case RESULT_FAILURE_ERROR: + dealErrorDataNormal(msg); + break; + default: + throw new RuntimeException("un reached state -- surveyor"); + } + } + + private void startCheckTolerance() { + checkTolerance(this::dealCheckToleranceResult); + } + + @Override + protected void quite() { + super.quite(); + surveyorImpl().exitSurveyor(); + } + + @Override + protected void resume() { + getSurveyorData().clearSurveyState(); + } + + @Override + public void remindUserAimingAtWire() { + //退出测量 + surveyorImpl().exitSurveyor(); + navigation2(StateType.doWellMeasureRotationReady); + } + + private void dealErrorDataNormal(String msg) { + surveyorImpl().exitSurveyor(); + SurveyStateEvent.postFailure(); + //进入失败状态 + Bundle args = _SurveyorFailureStateVer.args(msg); + navigation2(StateType.SurveyorFailure, args); + } + + + @Override + public void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + //重置错误读数 + failureCount = 0; + if (getSurveyorData().onSurveyor(originalHa, originalVa, sd, hd)) { + //测量数据成功,可以退出测量状态 + refreshUI(); + if (checkSurveyorFirstLeftOrRight()) { + onSuccess(); + } + } else {//测量数据不完全,需要继续测量 + refreshUI(); + if (checkSurveyorFirstLeftOrRight()) { + // + getSurveyorData().setMeasureTimes(1); + surveyorIndex = 1;//更新测量索引 + sendSurveyRequestNext(); + } + } + } + + @Override + public void onError(String errorMsg) { + TtsManager.getInstance().speak(errorMsg); + if (allowTryWhenFailure) {//允许重新测量 + if (!isLive()) { + return; + } + //测量出现异常,需要处理 + failureCount++; + if (failureCount >= MAX_SURVEYOR_COUNT) { + if (isAutoSurveyOpen()) { + TtsManager.getInstance().speak("多次测量未成功,已暂停,请检查"); + } + onCompleted(RESULT_FAILURE_EXCEED_MAX, "多次尝试测量未能成功"); + } else { + //再次尝试 + sendSurveyRequest(); + Toast.makeText(getContext(), "接收数据超时,再次尝试测量", Toast.LENGTH_SHORT).show(); + } + } else { + onCompleted(RESULT_FAILURE_ERROR, errorMsg); + } + } + + +} + + diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_IdleStateVer.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_IdleStateVer.java new file mode 100644 index 0000000..bc59b85 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_IdleStateVer.java @@ -0,0 +1,134 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle; + +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.bingce.controlapphelper.model.DataCategory; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.event.RefreshRollBackEvent; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.totalstation.ControlSurveyResult; + +import net.tatans.tensorflowtts.tts.TtsManager; + +import org.greenrobot.eventbus.EventBus; + +import blankj.utilcode.util.ToastUtils; + + +/** + * 空闲状态 + *

+ * 将刷新界面 + */ +class _IdleStateVer extends __BaseStateVer { + @NonNull + private final IAutoModeSwitcher autoModeSwitcher; + + public _IdleStateVer(StateManagerSeparateVerAngle stateManager, @NonNull IAutoModeSwitcher autoModeSwitcher) { + super(StateType.idle, stateManager); + this.autoModeSwitcher = autoModeSwitcher; + } + + @Override + public void enter(Bundle args) { + int currentCycleIndexLast = getCurrentCycleIndex(); + if (currentCycleIndexLast == -1) { + postCompleteEvent(); + return; + } + + int currentPointIndexLast = getCurrentItemIndex(); + VerAngleFindIndexUtil.VerFindTarget frontTarget = VerAngleFindIndexUtil.findFront(stationId(), getCachedData(), currentPointIndexLast, getCycleCount()); + setSurveyorData(frontTarget, true); + //刷新页面数据 + refreshUiPosition(); + //刷新回退按钮 + refreshGoBackButton(); + if (frontTarget.getCycleIndex() == -1) { + //没有可以测量的数据了 + doSurveyorSuccess(); + return; + } + + //有需要测的数据开始判断是否满足自动测量条件 + //判断当前条件是否满足自动测量 + autoModeSwitcher.isReadyAutoSurvey(isReadyCode -> { + boolean isReady = isReadyCode == ControlSurveyResult.CODE_SUCCESS; + + if (isReady) { + //判断是否继续自动测量 + boolean isSwitchCycle = currentCycleIndexLast != frontTarget.getCycleIndex(); + if (isSwitchCycle && autoModeSwitcher.isAutoModeInit()) { + //用户选择后会发送通知,更新测量按钮UI + tips4StartAutoSurvey(autoModeSwitcher); + } else if (autoModeSwitcher.isAutoModeOpen()) { + if (isLive()) { + //继续测量 + Log.d("hwhw", "从空闲状态进入测量状态"); + navigation2(StateType.doSurveyor); + } else { + autoModeSwitcher.resetAutoMode(); + postIdleEvent(); + } + } + } else { + if (ControlSurveyResult.isAbandon(isReadyCode) != null) { + String msg = ControlSurveyResult.isAbandon(isReadyCode); + if (!TextUtils.isEmpty(msg)) { + ToastUtils.showShort(msg); + } + resetSurveyForReadyAndComplete(false, false); + } else { + autoModeSwitcher.resetAutoMode(); + postIdleEvent(); + } + } + }); + + } + + @Override + protected void resume() { + autoModeSwitcher.resetAutoMode(); + postIdleEvent(); + } + + private void resetSurveyForReadyAndComplete(boolean isReady, boolean completed) { + //如果自动测量打开了,但是没有进入测量状态 + //需要将自动测量开关重置 + if (autoModeSwitcher.isAutoModeOpen()) { + autoModeSwitcher.resetAutoMode(); + } + postIdleEvent(); + } + + private void refreshGoBackButton() { + int itemIndex = getCurrentItemIndex(); + String pointId = getCachedData().pointId(0, itemIndex); + DataCategory dataCategory = getCachedData().valueState( + IdUtil.surveyorRecordKey(stationId(), 0, pointId, LeftOrRight.left), 0); + + int fragmentPosition = RefreshRollBackEvent.getFragmentPosition(measureWhat(), getStation().isSeparateObservation()); + + EventBus.getDefault().post(new RefreshRollBackEvent(!dataCategory.isEmptyData(), fragmentPosition)); + } + + private void doSurveyorSuccess() { + //通知刷新 + postCompleteEvent(); + tips(getContext().getString(R.string.tips_all_cycle_has_finish_and_checked), null); + + if (isAutoSurveyOpen()) { + autoModeSwitcher.resetAutoMode(); + runOnUI(() -> TtsManager.getInstance().speak(getContext().getString(R.string.tips_all_cycle_has_finish_and_checked))); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_SurveyorFailureState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_SurveyorFailureStateVer.java similarity index 61% rename from app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_SurveyorFailureState.java rename to app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_SurveyorFailureStateVer.java index 43527b3..2f795ee 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/heighttraverse/_SurveyorFailureState.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/_SurveyorFailureStateVer.java @@ -1,20 +1,19 @@ -package com.bingce.controlnetwork.surveyor.state.heighttraverse; +package com.bingce.controlnetwork.surveyor.state.separateVerAngle; import android.os.Bundle; -import com.bingce.controlapphelper.surveyor.state.StateType; -import com.bingce.controlapphelper.util.Tools; -import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.state.StateType; + /* * 仪器导致的测量失败 * * 全站仪多次测量失败,进入该状态 * */ -class _SurveyorFailureState extends __BaseState { +class _SurveyorFailureStateVer extends __BaseStateVer { - public _SurveyorFailureState(int positionFragment, StateManagerHeightTraverse stateManager) { - super(StateType.SurveyorFailure, positionFragment, stateManager); + public _SurveyorFailureStateVer(StateManagerSeparateVerAngle stateManager) { + super(StateType.SurveyorFailure, stateManager); } @Override @@ -27,9 +26,10 @@ class _SurveyorFailureState extends __BaseState { } if (isShowDialog) { - failureTipsWithAutoStandStill(error + Tools.getString(R.string.please_observe_target)); + tips(error + ",请重新观测该目标.", this::clearSurveyorStateAndEnterIdle); } else { - enterIdleAndClearSurveyStateAndResetAutoMode(true); + autoModeRecorder().resetAutoMode(); + clearSurveyorStateAndEnterIdle(); } } diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/__BaseStateVer.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/__BaseStateVer.java new file mode 100644 index 0000000..6e44bc3 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/separateVerAngle/__BaseStateVer.java @@ -0,0 +1,419 @@ +package com.bingce.controlnetwork.surveyor.state.separateVerAngle; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.fragment.BottomSheetSelectListFragment; +import com.bingce.controlnetwork.fragment.TipsFragment; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.state.base.AbstructState; +import com.bingce.totalstation.TotalStation; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.ArrayList; +import java.util.List; + +public abstract class __BaseStateVer extends AbstructState { + + + public __BaseStateVer(final StateType stateType, final StateManagerSeparateVerAngle stateManager) { + super(stateType, stateManager); + } + + + /** + * 设置测量位置 + */ + @Override + protected void setSurveyPosition(int index, LeftOrRight leftOrRight) { + //使用setSurveyorData代替 + } + + protected void setSurveyorData(VerAngleFindIndexUtil.VerFindTarget target, boolean isClearSurveyorState) { + if (stateManager != null) { + StateManagerSeparateVerAngle manager = (StateManagerSeparateVerAngle) stateManager; + manager.setSurveyorData(target, isClearSurveyorState); + } + } + + protected void clearSurveyorState() { + //清空当前的测量状态 + getSurveyorData().clearSurveyState(); + } + + /** + * 测量中断后恢复之前的测量状态 + * + * @param surveyorData + * @param cycleRecorder + */ + protected void recoverIdleSurveyorState(ISurveyorData surveyorData, ICycleRecorder cycleRecorder) { + setCurrentItemIndex(surveyorData.currentIndex()); + setCurrentCycleIndex(cycleRecorder.currentCycleIndex()); + setCurrentLeftOrRight(surveyorData.leftOrRight()); +// //清空当前的测量状态 +// surveyorData.clearSurveyState(); + + SurveyStateEvent.postIdle(); + + autoModeRecorder().resetAutoMode(); + setStateManagerCuttentState(StateType.idle); + + refreshUI(); + } + + final protected void failureTipsWithAutoStandStill(String msg, Runnable runnable) { + if (!isLive()) { + return; + } + SurveyStateEvent.postIdle(); + TipsFragment.noCancelAbleTips(fragmentManager(), lifecycleOwner(), + getContext(), + msg, + -1, + () -> { + if (runnable != null) { + runnable.run(); + } + clearSurveyorState(); + refreshUI(); + setStateManagerCuttentState(StateType.idle); + }); + } + +// final protected void optionTipsWithStandStill(String msg, Runnable confirmCallback) { +// optionTips(msg, null, null, +// confirmCallback, +// () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), +// () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); +// } +// +// /** +// * 提供选择操作 +// * 如果用户选择忽略,则自动保持原地不动,进入idle状态 +// */ +// final protected void optionTipsWithStandStill( +// String msg, String confirmButton, String cancelButton, Runnable confirmCallback) { +// optionTips(msg, confirmButton, cancelButton, +// confirmCallback, +// () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), +// () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); +// } + + +// protected final void option4Jump2OtherCycle4Resurvey(int cycleIndex) { +// option4Jump2OtherCycle(cycleIndex, true); +// } +// +// protected final void option4Jump2OtherEmptyCycle(int cycleIndex) { +// option4Jump2OtherCycle(cycleIndex, false); +// } + +// private void option4Jump2OtherCycle(int cycleIndex, boolean resurveyOrEmpty) { +// String msg = "有待测数据,是否跳转到该处继续."; +// if (resurveyOrEmpty) { +// msg = "有待补测数据,是否跳转到该处继续."; +// } +// optionTips("在" + SurveyorCycleUtil.cycleName(cycleIndex) + msg, +// null, +// null, +// () -> { +// //切换测回 +// getCycleRecorder().changeCycleIndex(cycleIndex); +// //数据库存储修改当前测回 +// setStationCycle(cycleIndex); +// //查找测量目标 +// findTargetFromBeginInCurrentCycle(false); +// }, +// () -> enterIdleAndClearSurveyStateAndResetAutoMode(true), +// () -> enterIdleAndClearSurveyStateAndResetAutoMode(true)); +// } + + + @Override + final protected void setStationCycle(int cycle) { + getCycleRecorder().changeCycleIndex(cycle); +// TjDbFactory +// .instance +// .getScheduleDataSource() +// .record( +// new SurveyorScheduleRecord( +// SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), stateManager.getMeasureWhat()), +// String.valueOf(cycle))); + } + + @Override + final protected void setStationScheduleForSingleCycle(int cycleIndex, String statue) { +// TjDbFactory +// .instance +// .getScheduleDataSource() +// .record( +// new SurveyorScheduleRecord( +// SurveyorScheduleConstants.stationSingleCycleScheduleKey(stationId(), stateManager.getMeasureWhat(), cycleIndex), +// statue)); + } + + @Override + final protected void setStationScheduleForAllCycle(String statue) { + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationAllCycleScheduleKey(stationId(), stateManager.getMeasureWhat()), + statue)); + } + + + @Override + protected int getCycleCount() { + // TODO: 2024/8/30 + return getToleranceRecord().getCycleCount(); + } + + private VerAngleCheckTolerance getVerAngleCheckTolerance() { + StateManagerSeparateVerAngle manager = (StateManagerSeparateVerAngle) stateManager; + return manager.getVerAngleCheckTolerance(); + } + + protected void checkTolerance(VerAngleCheckTolerance.IVerAngleCheckToleranceCallBack callBack) { + getVerAngleCheckTolerance().checkToleranceAndSave(measureWhat(), stationId(), getCachedData(), + getSurveyorData(), getCycleRecorder().currentCycleIndex(), getToleranceRecord(), + callBack); + } + + protected void clearSurveyorStateAndEnterIdle() { + clearSurveyorState(); + navigation2(StateType.idle); + } + + + public void dealCheckToleranceResult(int code, String msg) { + ThreadPoolUtil.executeInMain(() -> { + if (code == VerAngleCheckTolerance.CODE_ERROR_TIPS) { + tips(msg, this::clearSurveyorStateAndEnterIdle); + } else if (code == VerAngleCheckTolerance.CODE_ERROR_NEED_REMEASURE) { + showReMeasureDialog(msg); + } else { + navigation2(StateType.idle); + } + }); + } + + private void showReMeasureDialog(String msg) { + optionTips(msg, "重测测回", null, + this::showSelectDeleteCycleDialog, + () -> { + markCurrentDirtyData(); + setOnlyIdleState(); + }, + () -> { + markCurrentDirtyData(); + setOnlyIdleState(); + }); + } + + + private void markCurrentDirtyData() { + List pointIds = new ArrayList<>(); + pointIds.add(getCurrentPointId()); + getCachedData().markReSurveyor(stationId(), getCurrentCycleIndex(), pointIds); + } + + private void markDirtyData(int cycleIndex, List pointIds) { + getCachedData().markReSurveyor(stationId(), cycleIndex, pointIds); + } + + public void showRollBackDialog(VerAngleFindIndexUtil.VerFindTarget target) { + optionTips("是否回退上一测回数据,这将删除原数据?", null, null, + () -> { + ISurveyorData surveyorData = getSurveyorData(); + if (surveyorData.hasSurveyor2()) { + surveyorData.restoreSurveyor1(); + } else { + surveyorData.clearSurveyState(); + } + //删除数据 + getCachedData().deleteSurveyorRecord(stationId(), target.getCycleIndex(), + target.getPointIndex(), target.getLeftOrRight()); + + setSurveyorData(target, false); + refreshUiPosition(); + postIdleEvent(); + }, + null, + null); + } + + protected void refreshUiPosition() { + refreshUI(); + scroll2(getCurrentCycleIndex(), getCurrentItemIndex()); + } + + protected void postIdleEvent() { + SurveyStateEvent.postIdle(); + } + + protected void postSurveyoringEvent() { + SurveyStateEvent.postSurveying(); + } + + protected void postCompleteEvent() { + SurveyStateEvent.postCompleted(); + } + + public void startDeleteOneCycleData(VerAngleFindIndexUtil.VerFindTarget target) { + if (target == null) { + showSelectDeleteCycleDialog(); + return; + } + optionTips(Tools.getString(R.string.tips_delete_current_cycle_surveyor_record), null, null, + () -> { + doDeleteCacheDataCurrentCycle(target); + }, + null, + null); + } + + private void doDeleteCacheDataCurrentCycle(VerAngleFindIndexUtil.VerFindTarget target) { + //删除数据 + getCachedData().deleteSurveyorRecord(stationId(), target.getCycleIndex(), + target.getPointIndex(), LeftOrRight.left); + getCachedData().deleteSurveyorRecord(stationId(), target.getCycleIndex(), + target.getPointIndex(), LeftOrRight.right); + setSurveyorData(target, true); + refreshUiPosition(); + setOnlyIdleState(); + } + + public void showPointAllCycleDialog() { + optionTips("是否删除该测点的所有测回数据?", null, null, + this::doDeletePointAllCycle, + null, + null); + } + + private void doDeletePointAllCycle() { + for (int cycleIndex = 0; cycleIndex < getCycleCount(); cycleIndex++) { + getCachedData().deleteSurveyorRecord(stationId(), cycleIndex, getCurrentItemIndex(), LeftOrRight.left); + getCachedData().deleteSurveyorRecord(stationId(), cycleIndex, getCurrentItemIndex(), LeftOrRight.right); + } + setSurveyorData(new VerAngleFindIndexUtil.VerFindTarget(0, getCurrentItemIndex(), LeftOrRight.left), true); + refreshUiPosition(); + postIdleEvent(); + } + + /** + * 弹框提示用户是否开启自动测量 + */ + protected void tips4StartAutoSurvey(IAutoModeSwitcher autoModeSwitcher) { + // TODO: 2024/8/30 +// runOnUI(() -> +// TipsWith2OptionFragment.tips( +// fragmentManager(), +// lifecycleOwner(), +// getContext().getString(R.string.hint), +// null, +// null, +// null, +// getContext().getString(R.string.tips_finish_study_should_auto_survey), +// -1, +// false, +// new TipsWith2OptionFragment.SimpleCallback() { +// @Override +// public void onConfirm() { +// TtsManager.getInstance().speak("开始自动测量"); +// autoModeSwitcher.openAutoMode(); +// navigation2(StateType.doSurveyor); +// postSurveyoringEvent(); +// } +// +// @Override +// public void onCancel() { +// autoModeSwitcher.closeAutoMode(); +// +// postIdleEvent(); +// } +// +// @Override +// public void onIgnore() { +// autoModeSwitcher.closeAutoMode(); +// +// postIdleEvent(); +// } +// } +// )); + } + + /** + * 如果是测回内首次盘左或盘右测量,需要校验并换面 + */ + protected boolean checkSurveyorFirstLeftOrRight() { + LeftOrRight leftOrRight = getSurveyorData().leftOrRight(); + + int measureTimes = getSurveyorData().getMeasureTimes(); + if (measureTimes == 0) { + double angleVer1 = getSurveyorData().getAngleVer1(); + if (leftOrRight == LeftOrRight.right) { + if (isLeftVerAngle(angleVer1)) { + failureTipsWithAutoStandStill(Tools.getString(R.string.error_tips_please_start_from_right), + () -> TotalStation.getInstance().requestChangeFace()); + return false; + } + } else { + //盘左 + if (!isLeftVerAngle(angleVer1)) { + failureTipsWithAutoStandStill(Tools.getString(R.string.error_tips_please_start_from_left), + () -> TotalStation.getInstance().requestChangeFace()); + return false; + } + } + } + return true; + } + + private boolean isLeftVerAngle(double vAngle) { + return vAngle >= 0 && vAngle <= Math.PI; + } + + + private void showSelectDeleteCycleDialog() { + int cycleCount = getCycleCount(); + ArrayList cycleList = new ArrayList<>(); + for (int i = 0; i < cycleCount; i++) { + cycleList.add("第" + (i + 1) + "测回"); + } + + setOnlyIdleState(); + BottomSheetSelectListFragment.showSelect( + fragmentManager(), + lifecycleOwner(), + getCurrentCycleIndex(), + cycleList, + null,//不再限制测期 + (index, string) -> { + int pointCount = getCachedData().realPointCount(); + if (pointCount == 0) { + return; + } + VerAngleFindIndexUtil.VerFindTarget target = + new VerAngleFindIndexUtil.VerFindTarget(index, getCurrentItemIndex(), getCurrentLeftOrRight()); + + doDeleteCacheDataCurrentCycle(target); + }); + } + + private void setOnlyIdleState() { + SurveyStateEvent.postIdle(); + setStateManagerCuttentState(StateType.idle); + } + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/IWeatherShowDialogListener.kt b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/IWeatherShowDialogListener.kt new file mode 100644 index 0000000..6acdbe4 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/IWeatherShowDialogListener.kt @@ -0,0 +1,11 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance + +interface IWeatherShowDialogListener { + fun show( + stationId: String, + currentCycleIndex: Int, + pointId: String, + beforeOrAfter: Int, + msg: String, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/StateManagerWell.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/StateManagerWell.java new file mode 100644 index 0000000..0329884 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/StateManagerWell.java @@ -0,0 +1,270 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance; + +import android.content.Context; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.LifecycleOwner; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.util.IUIRunner; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IStationPointRecordCollect; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.state.ISurveyorDataScrollDelegate; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.state.base.AbstructStateManager; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.util.SupportAutoSurveyorUtil; +import com.bingce.utils.ThreadPoolUtil; + + +public class StateManagerWell extends AbstructStateManager { + public final IWeatherShowDialogListener showWeatherListener; + private boolean isAlreadyRemindUserAimingAtWire; + + private StateManagerWell(final boolean supportAutoSurvey,//是否支持自动测量 + final @NonNull SurveyorStationRecord stationRecord, + final @NonNull PointRecord stationPointRecord, + final @NonNull ToleranceDetailRecord toleranceRecord, + final @NonNull Context context, + final @NonNull IStationPointRecordCollect pointRecordCollect, + final @NonNull ISurveyorData surveyorData, + final @NonNull ICycleRecorder cycleRecorder, + @NonNull ICachedData cachedData, + final @NonNull ISurveyorDataScrollDelegate scrollDelegate, + FragmentManager fragmentManager, + LifecycleOwner lifecycleOwner, + IUIRunner iuiRunner, + IWeatherShowDialogListener showWeatherListener) { + super(StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE, supportAutoSurvey, stationRecord, stationPointRecord, + toleranceRecord, context, pointRecordCollect, surveyorData, cycleRecorder, + cachedData, scrollDelegate, fragmentManager, lifecycleOwner, iuiRunner); + this.showWeatherListener = showWeatherListener; + } + + @Override + protected void initState() { + _DoSurveyorState doSurveyorState = new _DoSurveyorState(this, this); + stateMap.put(StateType.idle, new _IdleState(this)); + stateMap.put(StateType.doSurveyor, doSurveyorState); + stateMap.put(StateType.checkTolerance, new _CheckToleranceState(this, this)); + } + + @Override + protected void refreshUiPage() { + if (refreshFragmentUiListener != null) { + refreshFragmentUiListener.refresh(); + } + } + + public void doSurveyor() { + if (isInValidate()) { + return; + } + if (Tools.isDeviceConnectedNot()) { + return; + } + ThreadPoolUtil.execute(() -> getBaseState().checkSurveyorBefore()); + } + + /** + * 删除点的所有测回记录 + */ + public void deletePointAllCycleData() { + if (isInValidate()) { + return; + } + getBaseState().deletePointAllCycleData(); + } + + /** + * 删除点的所有测回记录 + */ + public void deletePointCurrentCycleData() { + if (isInValidate()) { + return; + } + getBaseState().deletePointCurrentCycleData(); + } + + public void moveBack() { + if (isInValidate()) { + return; + } + getBaseState().moveBack(); + } + + public void stationCheck() { + if (isInValidate()) { + return; + } + enter(StateType.checkStation); + } + + public void stationAdjust() { + if (isInValidate()) { + return; + } + getBaseState().doAdjust(); + } + + /** + * 切换测回时触发 + * + * @param cycleIndex + */ + public void switch2Cycle(int cycleIndex) { + //由于井定向的距离测量是不用切换测回的,在一个页面展示了两个测回 +// if (isInValidate()) { +// return; +// } +// _DoCalScheduleInSingleCycleState.enter(this, cycleIndex); + } + + /** + * 进入开始测量的时候触发 + */ + public void calScheduleWhenEnterSurveyFragment() { + if (getCachedData().realPointCount()==0) { + return; + } + + if (isInValidate()) { + return; + } + Bundle bundle = new Bundle(); + bundle.putBoolean(SurveyorWellConstant.KEY_FIRST_CHECK_TOLERANCE, true); + enter(StateType.checkTolerance, bundle); + } + + //检测当前状态是否支持从外界主动改变状态 + //如果是空闲或者是测站通过检测是有效的状态 + private boolean isInValidate() { + return currentStateType != StateType.idle; + } + + @WorkerThread + public static StateManagerWell newInstance(@NonNull SurveyorStationRecord stationRecord, + @NonNull Context context, + @NonNull FragmentManager fragmentManager, + @NonNull LifecycleOwner lifecycleOwner, + @NonNull ToleranceDetailRecord toleranceRecord, + @NonNull IStationPointRecordCollect pointRecordCollect, + @NonNull ISurveyorData surveyorData, + @NonNull ICycleRecorder cycleRecorder, + @NonNull ICachedData cachedData, + ISurveyorDataScrollDelegate scrollDelegate, + IUIRunner runner, + IWeatherShowDialogListener weatherShowDialogListener) { + //读取测点record + String stationPointId = null; + if (stationRecord.getItems() != null) { + for (SurveyorPoint stationItem : stationRecord.getItems()) { + if (SurveyorPoint.TYPE_STATION.equals(stationItem.getType())) { + stationPointId = stationItem.getPointId(); + break; + } + } + } + PointRecord stationPointRecord = null; + if (stationPointId != null) { + stationPointRecord = SurveyorDatabaseFactory + .instance + .getPointDataSource() + .findByIdSync(stationPointId); + } + if (stationPointRecord == null) { + return null; + } + + boolean supportAuto = SupportAutoSurveyorUtil.isSupportAuto(); + + int surveyorIndex = WellDistanceFindIndexUtil.findSurveyorIndex(stationRecord.getId(), cachedData); + surveyorData.setCurrentIndex(surveyorIndex); + + return new StateManagerWell(supportAuto, + stationRecord, + stationPointRecord, + toleranceRecord, + context, + pointRecordCollect, + surveyorData, + cycleRecorder, + cachedData, + scrollDelegate, + fragmentManager, lifecycleOwner, runner, weatherShowDialogListener); + } + + @Override + protected ISurveyorListener getISurveyorListener() { + return getDoSurveyorState(); + } + + @Override + protected ISurveyorRemindListener getISurveyorRemindListener() { + return getDoSurveyorState(); + } + + private _DoSurveyorState getDoSurveyorState() { + return (_DoSurveyorState) stateMap.get(StateType.doSurveyor); + } + + @Override + public boolean isSurveying() { + return currentStateType == StateType.doSurveyor || currentStateType == StateType.doAutoSurveyor; + } + + @Override + public boolean isAutoSurveying() { + return isAutoModeOpen(); + } + + public interface IRefreshFragmentUi { + void refresh(); + } + + private IRefreshFragmentUi refreshFragmentUiListener; + + public void setRefreshFragmentUiListener(IRefreshFragmentUi refreshFragmentUiListener) { + this.refreshFragmentUiListener = refreshFragmentUiListener; + } + + public void setCurrentIndex(int itemIndex) { + getSurveyorData().setCurrentIndex(itemIndex); + } + + public void setCurrentCycleIndex(int cycleIndex) { + getCycleRecorder().changeCycleIndex(cycleIndex); + } + + public void refeshRollBackBtn() { + __BaseState baseState = getBaseState(); + if (baseState != null) { + baseState.postRefreshGoBackButtonWellSteelEvent(); + } + } + + private __BaseState getBaseState() { + return (__BaseState) getCurrentState(); + } + + public boolean isAlreadyRemindUserAimingAtWire() { + return isAlreadyRemindUserAimingAtWire; + } + + public void setAlreadyRemindUserAimingAtWire(boolean alreadyRemindUserAimingAtWire) { + isAlreadyRemindUserAimingAtWire = alreadyRemindUserAimingAtWire; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/SurveyorWellConstant.kt b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/SurveyorWellConstant.kt new file mode 100644 index 0000000..c8ad801 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/SurveyorWellConstant.kt @@ -0,0 +1,5 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance + +object SurveyorWellConstant { + const val KEY_FIRST_CHECK_TOLERANCE = "key_first_check_tolerance" +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/WellDistanceFindIndexUtil.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/WellDistanceFindIndexUtil.java new file mode 100644 index 0000000..f768002 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/WellDistanceFindIndexUtil.java @@ -0,0 +1,37 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance; + +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.util.IdUtil; + +public class WellDistanceFindIndexUtil { + + /** + * 查找测量点的index + * + * @return + */ + public static int findSurveyorIndex(String stationId, ICachedData cachedData) { + int pointCount = cachedData.realPointCount(); + + if (pointCount == 0) { + return -1; + } + + for (int itemIndex = 0; itemIndex < pointCount; itemIndex++) { + String pointId = cachedData.pointId(0, itemIndex); + String recordKey = IdUtil.surveyorRecordKey(stationId, 0, pointId, LeftOrRight.left); + AloneDistanceRecord wellRecord = cachedData.getWellRecord(recordKey); + + int num = cachedData.getSurveyorCount() * ToleranceDetailRecord.ALONE_DISTANCE_CYCLE_COUNT; + + if (!(wellRecord != null && wellRecord.distanceValues != null && wellRecord.distanceValues.size() >= num)) { + return itemIndex; + } + } + return -1; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_CheckToleranceState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_CheckToleranceState.java new file mode 100644 index 0000000..2051cfc --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_CheckToleranceState.java @@ -0,0 +1,172 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance; + +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; + +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.alonedistance.WellDistance; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.surveyor.method.ExportUtils; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.List; + +/** + * 检测当前测量数据读数互差 + */ +public class _CheckToleranceState extends __BaseState { + private final IAutoModeSwitcher autoModeSwitcher; + + private boolean initFirstCheck; + + public _CheckToleranceState(StateManagerWell stateManager, IAutoModeSwitcher autoModeSwitcher) { + super(StateType.checkTolerance, stateManager); + this.autoModeSwitcher = autoModeSwitcher; + } + + @Override + public void enter(Bundle args) { + Log.d("hwhw", "进入_CheckToleranceState"); + initFirstCheck = false; + if (args != null) { + initFirstCheck = args.getBoolean(SurveyorWellConstant.KEY_FIRST_CHECK_TOLERANCE, false); + } + ThreadPoolUtil.execute(this::doCheck); + } + + + public void doCheck() { + ICachedData cachedData = getCachedData(); + int surveyorCount = getSurveyorCount(); + int cycleCount = getCycleCount(); + + for (int i = 0; i < cachedData.realPointCount(); i++) { + String pointName = cachedData.pointName(0, i); + AloneDistanceRecord wellRecord = getWellRecord(i); + + if (wellRecord != null && wellRecord.distanceValues != null) { + //第一测回完成 + if (wellRecord.distanceValues.size() <= surveyorCount) { + boolean dataError = checkAndGoReadDataError(pointName, wellRecord.distanceValues, i); + if (dataError) return; + } else if (wellRecord.distanceValues.size() >= surveyorCount * cycleCount) { + List valuesFirst = wellRecord.distanceValues.subList(0, surveyorCount); + List valuesSecond = wellRecord.distanceValues.subList(surveyorCount, surveyorCount * 2); + + boolean dataError = checkAndGoReadDataError(pointName, valuesSecond, i); + if (dataError) return; + + String cycleError = getCycleError(pointName, valuesFirst, valuesSecond); + if (!TextUtils.isEmpty(cycleError)) { + goToError(cycleError, i); + return; + } + + } + } + } + + onSuccess(); + + } + + private boolean checkAndGoReadDataError(String pointName, List distanceValues, int itemIndex) { + String readDataError = getReadDataError(pointName, distanceValues); + if (!TextUtils.isEmpty(readDataError)) { + goToError(readDataError, itemIndex); + return true; + } + return false; + } + + private String getReadDataError(String pointName, List distanceValues) { + double slopeReadDifference = getToleranceRecord().slopeReadDifference; + + double min = Double.MAX_VALUE; + double max = Double.MIN_VALUE; + for (int j = 0; j < distanceValues.size(); j++) { + double slopDistance = distanceValues.get(j).slopDistance; + if (min > slopDistance) { + min = slopDistance; + } + if (max < slopDistance) { + max = slopDistance; + } + } + + double readData = Math.abs(max - min) * 1000; + if (readData > slopeReadDifference) { + return "测站:" + pointName + ",测回内读数较差超限: " + ExportUtils.formatDistance(readData); + } + return null; + } + + private String getCycleError(String pointName, List valuesFirst, List valuesSecond) { + double distCyclesDifference = getToleranceRecord().slopeReadDifference; + Double averageFirst = Tools.calculateCollectionDoubleAverage(valuesFirst, true); + Double averageSecond = Tools.calculateCollectionDoubleAverage(valuesSecond, true); + + double distCyclesDifferenceData = Math.abs(averageFirst - averageSecond) * 1000; + + if (distCyclesDifferenceData > distCyclesDifference) { + return "测站:" + pointName + ",测回间距离较差超限: " + ExportUtils.formatDistance(distCyclesDifferenceData); +// wellRecord.distanceValues.remove(wellRecord.distanceValues.size() - 1); + } + return null; + } + + private void goToError(String msg, int errorItemIndex) { + setSurveyPosition(errorItemIndex, LeftOrRight.left); + runOnUI(() -> optionTipsWithStandStill(msg, null)); + } + + private void onSuccess() { + //测完检测完 + checkSurveyorAfter(initFirstCheck); + } + + /** + * 斜距两次读数差 + * + * @param distance1 读数1 + * @param distance2 读数2 + * @return 读数差(单位毫米) + */ + public static double distanceReadDiff(double distance1, double distance2) { + return Math.abs(distance1 - distance2) * 1000; + } + + + private static final int RESULT_YES = 0;//测回结束 + private static final int RESULT_NO = 1;//测回未结束 + + /** + * 判断单个测回是否测量完成(不要求通过检测) + * + * @param stationId + * @param cycleIndex + * @param cachedData + * @return + */ + public static boolean isCompleteAllPointForAloneDistance(String stationId, int cycleIndex, ICachedData cachedData) { + int result = RESULT_YES; + for (int index = 0; index < cachedData.realPointCount(); index++) { + String pointId = cachedData.pointId(cycleIndex, index); + String leftOrRightKey = IdUtil.surveyorRecordKey(stationId, cycleIndex, pointId, LeftOrRight.left); + AloneDistanceRecord wellRecord = cachedData.getWellRecord(leftOrRightKey); + if (wellRecord == null || wellRecord.distanceValues == null || + wellRecord.distanceValues.size() < ToleranceDetailRecord.ALONE_DISTANCE_CYCLE_COUNT * ToleranceDetailRecord.ALONE_DISTANCE_MEASURE_COUNT) { + result = RESULT_NO; + break; + } + } + return RESULT_YES == result; + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_DoSurveyorState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_DoSurveyorState.java new file mode 100644 index 0000000..645fccb --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_DoSurveyorState.java @@ -0,0 +1,207 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.widget.Toast; + +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.surveyor.state.ISurveyState; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorListener; +import com.bingce.controlnetwork.surveyor.surveyor.ISurveyorRemindListener; +import com.bingce.controlnetwork.surveyor.surveyor.RequestParam; +import com.bingce.device.Device; +import com.bingce.totalstation.TotalStation; +import com.bingce.totalstation.protocol.topcon.TopconInterface; +import com.bingce.utils.ThreadPoolUtil; + +import net.tatans.tensorflowtts.tts.TtsManager; + +import blankj.utilcode.util.ToastUtils; + + +/** + * 先检测是否有其他未完成测回,继续本次测量将删除其他测回数据 + */ +class _DoSurveyorState extends __BaseState implements ISurveyorListener, ISurveyorRemindListener { + private final ISurveyState surveyState; + //最多测量次数,如果5次测量都没有获取正常数据,则跳过 + private static final int MAX_SURVEYOR_COUNT = 3; + private static int failureCount = 0; + private static final int RESULT_SUCCESS = 0; + private static final int RESULT_FAILURE_EXCEED_MAX = 1;//测量失败次数超出最大限制 + private static final int RESULT_FAILURE_ERROR = 2;//测量失败,又没有允许重复尝试 + private static final boolean allowTryWhenFailure = true;//在测量失败的时候,是否允许重新测量 + + private int surveyorIndex = 0; + + private final Handler handler; + + public _DoSurveyorState(StateManagerWell stateManager, ISurveyState surveyState) { + super(StateType.doSurveyor, stateManager); + this.surveyState = surveyState; + handler = new Handler(Looper.getMainLooper()); + } + + @Override + public void enter(Bundle args) { + surveyorIndex = 0; + getSurveyorData().setMeasureTimes(0); + Log.d("hwhw", "进入__DoSurveyorState"); + doSurveyor(); + } + + private void doSurveyor() { + failureCount = 0; + //判断设备是否连接 + if (surveyorImpl().isReady()) { + // + ThreadPoolUtil.execute(() -> { + //发送测量信号 + SurveyStateEvent.postSurveying(); + //注册接收测量数据 + surveyorImpl().prepareSurveyor(); + + sendSurveyRequest(); + }); + + } else { + Device.getInstance().remindConnectDevice(); + enterIdle(); + } + } + + /** + * 接收 + */ + @Override + public void remindUserAimingAtWire() { + //停止接收数据 + surveyorImpl().exitSurveyor(); + + setIsAlreadyRotary(true); + String msg; + if (isWellSteel()) { +// msg = getContext().getString(R.string.please_aiming_at_wire_then_measure); + } else { +// msg = getContext().getString(R.string.please_aiming_at_no_prism_then_measure); + } +// runOnUI(() -> TtsManager.getInstance().speak(msg)); + + setIdleStateOnly(); + setBtnIdle(); + } + + private void sendSurveyRequest() { + SurveyorPoint surveyorPoint = getCachedData().getSurveyorPoint(getCycleRecorder().currentCycleIndex(), getCurrentItemIndex()); + int index = getSurveyorData().currentIndex(); + //isAlreadyRemindUserAimingAtWire为true时就是旋转到位了 + surveyorImpl().requestSurveyor(new RequestParam(StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE, getIsAlreadyRotary(), isWellSteel(), isAloneMeasureDistancePoint(), surveyorIndex, index, surveyorPoint)); + } + + private void onSuccess() { + onCompleted(RESULT_SUCCESS, ""); + } + + private void onCompleted(int result, String msg) { + //退出测量 + surveyorImpl().exitSurveyor(); + switch (result) { + case RESULT_SUCCESS://进入读数检测状态 + //检测是否处于「自动测量」 + if (!surveyState.isAutoSurveying()) { + SurveyStateEvent.postSuccess(); + } + navigation2(StateType.checkTolerance); + break; + case RESULT_FAILURE_EXCEED_MAX: + case RESULT_FAILURE_ERROR: { + //进入失败状态 + optionTipsWithStandStill(msg + ",请重新观测该目标.", null); + } + break; + default: + ToastUtils.showShort("未知错误"); + break; + } + } + + @Override + protected void quite() { + super.quite(); + surveyorImpl().exitSurveyor(); + } + + @Override + protected void resume() { + + } + + + @Override + public void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + //重置错误读数 + failureCount = 0; + //缓存数据 + AloneDistanceRecord wellDistanceRecord + = getCachedData().cacheWellDistance(0, getCurrentItemIndex(), sd, hd); + + if (wellDistanceRecord == null) return; + //刷新页面 + refreshUI(); + int surveyorCount = getCachedData().getSurveyorCount(); + if (wellDistanceRecord.distanceValues.size() == surveyorCount) { +// ToastUtils.showShort(App.getApp().getString(R.string.well_distance_first_round_measure_finish)); + setBtnIdle(); + onSuccess(); + } else if (wellDistanceRecord.distanceValues.size() >= surveyorCount * 2) { + setBtnIdle(); + onSuccess(); + } else { + //当数据不够的时候 继续发送指令 + surveyorIndex++; + getSurveyorData().setMeasureTimes(surveyorIndex); + if (isAutoSurveyOpen() && isLive()) { + if (TotalStation.getInstance() instanceof TopconInterface) { + //这个仪器需要延迟500毫秒发送指令 + handler.postDelayed(this::sendSurveyRequest, 500); + } else { + sendSurveyRequest(); + } + } else { + enterIdle(); + } + } + } + + @Override + public void onError(String errorMsg) { + TtsManager.getInstance().speak(errorMsg); + //检测,如果是仪器繁忙,退出测量状态 + if (allowTryWhenFailure) {//允许重新测量 + if (!isLive()) { + //死了就到这了 + return; + } + //测量出现异常,需要处理 + failureCount++; + if (failureCount >= MAX_SURVEYOR_COUNT) { + if (isAutoSurveyOpen()) { + TtsManager.getInstance().speak("多次测量未成功,已暂停,请检查"); + } + onCompleted(RESULT_FAILURE_EXCEED_MAX, "多次尝试测量未能成功"); + } else { + //再次尝试 + sendSurveyRequest(); + Toast.makeText(getContext(), "接收数据超时,再次尝试测量", Toast.LENGTH_SHORT).show(); + } + } else { + onCompleted(RESULT_FAILURE_ERROR, errorMsg); + } + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_IdleState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_IdleState.java new file mode 100644 index 0000000..5cba03b --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/_IdleState.java @@ -0,0 +1,50 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance; + +import android.os.Bundle; +import android.util.Log; + +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.utils.ThreadPoolUtil; + +/** + * 空闲状态 + *

+ * 将刷新界面 + */ +class _IdleState extends __BaseState { + + public _IdleState(StateManagerWell stateManager) { + super(StateType.idle, stateManager); + } + + @Override + public void enter(Bundle args) { + //更新回退按钮状态 + Log.d("hwhw", "进入idle"); + ThreadPoolUtil.execute(() -> { + int notFinishPoint = findNotFinishPoint(); + if (notFinishPoint == -1) { + setBtnCompleted(); + resetAutoSurveyor(); + setCurrentItemIndex(-1); + } else { + setBtnIdle(); + + int currentIndex = getSurveyorData().currentIndex(); + if (currentIndex == -1) { + setSurveyPosition(notFinishPoint, LeftOrRight.left); + } + } + postRefreshGoBackButtonWellSteelEvent(); + refreshUI(); + }); + } + + + @Override + protected void resume() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/__BaseState.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/__BaseState.java new file mode 100644 index 0000000..7835abf --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/state/wellDistance/__BaseState.java @@ -0,0 +1,561 @@ +package com.bingce.controlnetwork.surveyor.state.wellDistance; + +import android.util.Log; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.event.RefreshRollBackEvent; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.fragment.StationDataAdjustAloneVerOrDistanceDialogFragment; +import com.bingce.controlnetwork.model.AloneAdjustItem; +import com.bingce.controlnetwork.surveyor.method.AutoSurveyorMethod; +import com.bingce.controlnetwork.surveyor.method.SurveyorAdjustMethodTj; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.state.base.AbstructState; +import com.bingce.controlnetwork.surveyor.state.base.AbstructStateManager; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.utils.ThreadPoolUtil; + +import org.greenrobot.eventbus.EventBus; + +import java.util.List; + +import blankj.utilcode.util.ToastUtils; + + +public abstract class __BaseState extends AbstructState { + + public __BaseState(final StateType stateType, final AbstructStateManager stateManager) { + super(stateType, stateManager); + } + + /** + * 设置测量位置-前提是有未测的点 + */ + @Override + final protected void setSurveyPosition(int notFinishPointIndex, LeftOrRight leftOrRight) { + //设置即将要测的点的索引 + setCurrentItemIndex(notFinishPointIndex); + //重新设置测回 + setCurrentCycleIndex(getCycleIndexForAddOrDelete(notFinishPointIndex)); + getSurveyorData().setLeftOrRight(leftOrRight); + + setIsAlreadyRotary(false); + + runOnUI(() -> scroll2(getCurrentCycleIndex(), notFinishPointIndex)); + } + + private void showWeatherDialog(String msg, int beforeOrAfter) { + runOnUI(() -> { + StateManagerWell manager = (StateManagerWell) stateManager; + //显示弹框 + manager.showWeatherListener.show(stationId(), getCurrentCycleIndex(), getCurrentPointId(), beforeOrAfter, msg); + }); + } + + private String cycleIndexToChinese(int cycleIndex) { + if (cycleIndex == 0) { + return "一"; + } else if (cycleIndex == 1) { + return "二"; + } + return ""; + } + + protected int getCurrentItemIndex() { + int currentItemIndex = super.getCurrentItemIndex(); + if (currentItemIndex < 0) { + return 0; + } + return currentItemIndex; + } + + @Override + public String getCurrentPointId() { + return getCachedData().getSurveyorPoint(0, getCurrentItemIndex()).getPointId(); + } + + final protected void optionTipsWithStandStill(String msg, Runnable confirmCallback) { + SurveyStateEvent.postIdle(); + optionTips(msg, null, null, + () -> { + if (confirmCallback == null) { + enterIdle(); + } else { + confirmCallback.run(); + } + }, + this::enterIdle, + this::enterIdle); + } + + @Override + final protected void setStationCycle(int cycle) { + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationCurrentCycleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE), + String.valueOf(cycle))); + } + + @Override + final protected void setStationScheduleForSingleCycle(int cycleIndex, String statue) { + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationSingleCycleScheduleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE, cycleIndex), + statue)); + } + + @Override + final protected void setStationScheduleForAllCycle(String statue) { + SurveyorDatabaseFactory + .instance + .getScheduleDataSource() + .record( + new SurveyorScheduleRecord( + SurveyorScheduleConstants.stationAllCycleScheduleKey(stationId(), StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE), + statue)); + } + + final protected void enterIdle() { + navigation2(StateType.idle); + } + + protected void setIdleStateOnly() { + stateManager.setCurrentState(StateType.idle); + } + + @Override + protected int getCycleCount() { + return ToleranceDetailRecord.ALONE_DISTANCE_CYCLE_COUNT; + } + + + /** + * 测前和侧后的气象设置进度记录 + */ + protected void deleteTjSurveyorPointSchudeleAllPoint() { + ThreadPoolUtil.execute(() -> { + // TODO: 2024/8/30 +// ISurveyorPointScheduleDataSource surveyorPointScheduleDataSource = TjDbFactory.instance.getSurveyorPointScheduleDataSource(); +// int pointCount = getCachedData().realPointCount(); +// for (int itemIndex = 0; itemIndex < pointCount; itemIndex++) { +// String pointId = getCachedData().getSurveyorPoint(0, itemIndex).getPointId(); +// List surveyorPointSchedule = surveyorPointScheduleDataSource.getSurveyorPointScheduleByStationPoint(stationId(), pointId); +// surveyorPointScheduleDataSource.delete(surveyorPointSchedule); +// } + }); + } + + + protected int getPointCount() { + return getCachedData().realPointCount(); + } + + protected String getPointId(int cycleIndex, int itemIndex) { + return getCachedData().pointId(cycleIndex, itemIndex); + } + + protected String getPointName(int cycleIndex, int itemIndex) { + return getCachedData().pointName(cycleIndex, itemIndex); + } + + protected AloneDistanceRecord getWellRecord(int itemIndex) { + String pointId = getPointId(0, itemIndex); + String recordKey = IdUtil.surveyorRecordKey(stationId(), 0, pointId, LeftOrRight.left); + return getCachedData().getWellRecord(recordKey); + } + + protected boolean isWellRecordFinish(AloneDistanceRecord wellRecord) { + return wellRecord != null && wellRecord.distanceValues != null && wellRecord.distanceValues.size() >= getSurveyorCount() * getCycleCount(); + } + + protected boolean isWellRecordHasData(AloneDistanceRecord wellRecord) { + return wellRecord != null && wellRecord.distanceValues != null && wellRecord.distanceValues.size() > 0; + } + + protected boolean isWellRecordNoData(AloneDistanceRecord wellRecord) { + return wellRecord == null || wellRecord.distanceValues == null || wellRecord.distanceValues.isEmpty(); + } + + protected boolean isWellRecordFinishOneCycle(AloneDistanceRecord wellRecord) { + return wellRecord != null && wellRecord.distanceValues != null && wellRecord.distanceValues.size() == getSurveyorCount(); + } + + protected int getCycleIndexForAddOrDelete(int itemIndex) { + AloneDistanceRecord wellRecord = getWellRecord(itemIndex); + if (wellRecord == null || wellRecord.distanceValues == null || wellRecord.distanceValues.size() < getSurveyorCount()) { + return 0; + } + return 1; + } + + /** + * 查找未完成的测点 + */ + protected int findNotFinishPoint() { + int findIndex = -1; + + int pointCount = getPointCount(); + if (pointCount == 0) { + return findIndex; + } + + if (!isWellRecordFinish(getWellRecord(getCurrentItemIndex()))) { + return getCurrentItemIndex(); + } + + for (int itemIndex = 0; itemIndex < getPointCount(); itemIndex++) { + AloneDistanceRecord wellRecord = getWellRecord(itemIndex); + if (!isWellRecordFinish(wellRecord)) { + return itemIndex; + } + } + return findIndex; + } + + protected void isReadyAutoSurvey(AutoSurveyorMethod.CallBackLearnResultCode callBackLearnResultCode) { + stateManager.isReadyAutoSurvey(callBackLearnResultCode); + } + + protected void openAutoSurveyor() { + autoModeRecorder().openAutoMode(); + } + + protected void resetAutoSurveyor() { + autoModeRecorder().resetAutoMode(); + } + + protected void closeAutoSurveyor() { + autoModeRecorder().closeAutoMode(); + } + + protected boolean isAutoSurveying() { + return stateManager.isAutoSurveying(); + } + + protected void stopAutoSurvey() { + stateManager.closeAutoMode(); + } + + protected boolean isAutoSurveyInit() { + return stateManager.isAutoModeInit(); + } + + protected void setBtnSurveying() { + SurveyStateEvent.postSurveying(); + } + + protected void setBtnCompleted() { + SurveyStateEvent.postCompleted(); + } + + protected void setBtnIdle() { + SurveyStateEvent.postIdle(); + } + + protected void setBtnFailure() { + SurveyStateEvent.postFailure(); + } + + protected void deletePointAllCycleData() { + if (isCanDeleteCycleDataNot()) { + return; + } + int pointIndex = getCurrentItemIndex(); + optionTipsWithStandStill("是否删除该测点的所有测回数据?", + () -> { + ThreadPoolUtil.execute(() -> { + boolean deleteSuccess = getCachedData().deleteWellDistanceStationRecord(stationId(), pointIndex); + if (!deleteSuccess) { + ToastUtils.showShort("没有数据了"); + return; + } + + //重置进度 + setStationScheduleForSingleCycle(0, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + //pointIndex不需要重置 + setCurrentCycleIndex(0); + resetAutoSurveyor(); + refreshUI(); + enterIdle(); + }); + + }); + } + + protected void deletePointCurrentCycleData() { + if (isCanDeleteCycleDataNot()) { + return; + } + optionTipsWithStandStill("确定要删除当前测回数据吗?", + this::doMoveBackOrDeleteOneCycle); + } + + protected void moveBack() { + if (isCanDeleteCycleDataNot()) { + return; + } + optionTipsWithStandStill("确定要回退数据吗?", + this::doMoveBackOrDeleteOneCycle); + } + + private void doMoveBackOrDeleteOneCycle() { + ThreadPoolUtil.execute(() -> { + //删除当前数据 + int pointIndex = getCurrentItemIndex(); + boolean isDeleteSuccess = getCachedData().deleteWellDistancePointRecordOneCycle(stationId(), pointIndex); + if (!isDeleteSuccess) { + return; + } + + int cycleIndexForAddOrDelete = getCycleIndexForAddOrDelete(pointIndex); + + setCurrentCycleIndex(cycleIndexForAddOrDelete); + refreshUI(); + + enterIdle(); + //重置进度 + setStationScheduleForSingleCycle(0, SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED); + }); + } + + private boolean isCanDeleteCycleDataNot() { + int pointIndex = getSurveyorData().currentIndex(); + if (pointIndex == -1) { + ToastUtils.showShort("请先选择测点!"); + return true; + } + + boolean wellRecordNoData = isWellRecordNoData(getWellRecord(pointIndex)); + if (wellRecordNoData) { + ToastUtils.showShort("没有数据了"); + return true; + } + return false; + } + + protected void postRefreshGoBackButtonWellSteelEvent() { + AloneDistanceRecord wellRecordCurrent = getWellRecord(getCurrentItemIndex()); + boolean wellRecordHasData = isWellRecordHasData(wellRecordCurrent); + int fragmentPosition = RefreshRollBackEvent.getFragmentPosition(measureWhat(), getStation().isSeparateObservation()); + EventBus.getDefault().post(new RefreshRollBackEvent(wellRecordHasData, fragmentPosition)); + } + + protected void doAdjust() { + runOnBackground(() -> { + List adjustResult = SurveyorAdjustMethodTj.calAloneDistance(stationId(), getCachedData(), true); + StationDataAdjustAloneVerOrDistanceDialogFragment.showDialog(fragmentManager(), stateManager.getMeasureWhat(), adjustResult); + }); + } + + /** + * 测完某一测回后检测其他(气象设置) + */ + protected void checkSurveyorAfter(boolean initFirstCheck) { +// SurveyorPointScheduleRecord lastSurveyorPointSchedule = SurveyorDatabaseFactory.instance.getSurveyorPointScheduleDataSource().getLastSurveyorPointSchedule(stationId(), getCurrentPointId()); +// if (lastSurveyorPointSchedule != null) { +// if (lastSurveyorPointSchedule.isHighPrecision()) { +// if (checkHighWeatherAfterFinishNot()) { +// showWeatherDialog(getHighAfterHint(), WeatherAmendmentConstants.WHICH_TYPE_AFTER); +// enterIdle(); +// return; +// } +// } +// } + checkSurveyorAfterEnd(initFirstCheck); + } + + public void checkSurveyorAfterEnd(boolean isInitFirst) { + int notFinishPoint = findNotFinishPoint(); + + setSurveyPosition(notFinishPoint, LeftOrRight.left); + + if (!isInitFirst) { + if (notFinishPoint == -1) { + Log.d("hwhw", "//所有测点都完成"); + resetAutoSurveyor(); + setStationScheduleForAllCycle(SurveyorScheduleConstants.STATUE_VALUE_CHECKED); +// runOnUI(() -> tips(getContext().getString(R.string.tips_all_cycle_has_finish_and_checked), null)); + } + } + enterIdle(); + } + + /** + * 开始测量的检测 + */ + protected void checkSurveyorBefore() { + //开始测量前检查是否高精度测后是否完成 + //检查是否设置了气象修正, + // 如果是一般修正和不修正,看是否设置,如果是高精度修正看是否设置过 + //通过以上就继续直接进入测量 +// if (checkHighWeatherAfterFinishNot()) { +// showWeatherDialog(getHighAfterHint(), WeatherAmendmentConstants.WHICH_TYPE_AFTER); +// return; +// } +// +// //当数据完全时 +// if (isWellRecordFinish(getWellRecord(getCurrentItemIndex()))) { +// int notFinishPoint = findNotFinishPoint(); +// if (notFinishPoint != -1) { +// setCurrentItemIndex(notFinishPoint); +// scroll2(getCycleIndexForAddOrDelete(notFinishPoint), notFinishPoint); +// refreshUI(); +// return; +// } +// } + + //重新设置测回 + setCurrentCycleIndex(getCycleIndexForAddOrDelete(getCurrentItemIndex())); + +// SurveyorPointScheduleRecord lastSurveyorPointSchedule = TjDbFactory.instance.getSurveyorPointScheduleDataSource().getLastSurveyorPointSchedule(stationId(), getCurrentPointId()); +// if (lastSurveyorPointSchedule == null) { +// showWeatherDialog(getSetWeatherAmendTypeHint(), WeatherAmendmentConstants.WHICH_TYPE_BEFORE); +// return; +// } +// +// if (lastSurveyorPointSchedule.isHighPrecision()) { +// if (checkHighWeatherBeforeFinishNot()) { +// showWeatherDialog(getHighBeforeHint(), WeatherAmendmentConstants.WHICH_TYPE_BEFORE); +// return; +// } +// } else { +// //非高精度修正可以统一 +// if (AloneDistanceRecord.checkOrdinaryNoFinishNot(lastSurveyorPointSchedule.scheduleWeatherAmendmentBefore)) { +// showWeatherDialog(getSetWeatherAmendParamsHint(), WeatherAmendmentConstants.WHICH_TYPE_BEFORE); +// return; +// } +// } +// +// AloneDistanceRecord wellRecordCurrent = getWellRecord(getCurrentItemIndex()); +// if (isWellRecordNoData(wellRecordCurrent) && autoModeRecorder().isAutoModeInit()) { +// isReadyAutoSurvey(isReadyCode -> { +// if (isReadyCode == ControlSurveyResult.CODE_SUCCESS) { +// tips4StartAutoSurvey(); +// } else { +// navigation2(StateType.doSurveyor); +// } +// }); +// } else { +// navigation2(StateType.doSurveyor); +// } + navigation2(StateType.doSurveyor); + + } + + private String getHighAfterHint() { + return "请设置目标 " + getPointName(0, getCurrentItemIndex()) + " 第" + cycleIndexToChinese(getCurrentCycleIndex()) + "测回测后气象"; + } + + private String getHighBeforeHint() { + return "请设置目标 " + getPointName(0, getCurrentItemIndex()) + " 第" + cycleIndexToChinese(getCurrentCycleIndex()) + "测回测前气象"; + } + + private String getSetWeatherAmendTypeHint() { + return "请设置气象修正方式"; + } + + private String getSetWeatherAmendParamsHint() { + return "请设置气象修正参数"; + } + + + /** + * + */ + private boolean checkHighWeatherAfterFinishNot() { +// SurveyorPointScheduleRecord hithSchedule = TjDbFactory.instance.getSurveyorPointScheduleDataSource().getLastSurveyorPointSchedule(stationId(), getCurrentPointId()); +// if (hithSchedule != null && hithSchedule.isHighPrecision()) { +// SurveyorWellDistanceRecord wellRecordCurrent = getWellRecord(getCurrentItemIndex()); +// if (getCurrentCycleIndex() == 0 && isWellRecordFinishOneCycle(wellRecordCurrent)) { +// //第一测回测后 +// return SurveyorPointScheduleRecord.checkHighAfterFinishNot(stationId(), getCurrentCycleIndex(), getCurrentPointId()); +// } else if (getCurrentCycleIndex() == 1 && isWellRecordFinish(wellRecordCurrent)) { +// //第一测回测后 +// return SurveyorPointScheduleRecord.checkHighAfterFinishNot(stationId(), getCurrentCycleIndex(), getCurrentPointId()); +// } +// } + return false; + } + + /** + * + */ + private boolean checkHighWeatherBeforeFinishNot() { +// SurveyorWellDistanceRecord wellRecordCurrent = getWellRecord(getCurrentItemIndex()); +// if (getCurrentCycleIndex() == 0 && isWellRecordNoData(wellRecordCurrent)) { +// //第一测回测前 +// return SurveyorPointScheduleRecord.checkHighBeforeFinishNot(stationId(), getCurrentCycleIndex(), getCurrentPointId()); +// } else if (getCurrentCycleIndex() == 1 && isWellRecordFinishOneCycle(wellRecordCurrent)) { +// //第二测回测前 +// return SurveyorPointScheduleRecord.checkHighBeforeFinishNot(stationId(), getCurrentCycleIndex(), getCurrentPointId()); +// } + return false; + } + + protected boolean getIsAlreadyRotary() { + if (stateManager != null) { + StateManagerWell manager = (StateManagerWell) stateManager; + return manager.isAlreadyRemindUserAimingAtWire(); + } + return false; + } + + protected void setIsAlreadyRotary(boolean isAlready) { + if (stateManager != null) { + StateManagerWell manager = (StateManagerWell) stateManager; + manager.setAlreadyRemindUserAimingAtWire(isAlready); + } + } + + /** + * 弹框提示用户是否开启自动测量 + */ + private void tips4StartAutoSurvey() { +// runOnUI(() -> +// TipsWith2OptionFragment.tips( +// fragmentManager(), +// lifecycleOwner(), +// getContext().getString(R.string.hint), +// null, +// null, +// null, +// getContext().getString(R.string.tips_finish_study_should_auto_survey), +// -1, +// false, +// new TipsWith2OptionFragment.SimpleCallback() { +// @Override +// public void onConfirm() { +// TtsManager.getInstance().speak("开始自动测量"); +// openAutoSurveyor(); +// navigation2(StateType.doSurveyor); +// setBtnSurveying(); +// } +// +// @Override +// public void onCancel() { +// closeAutoSurveyor(); +// setBtnIdle(); +// } +// +// @Override +// public void onIgnore() { +// setBtnIdle(); +// } +// } +// )); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/IAutoSurveyor.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/IAutoSurveyor.java new file mode 100644 index 0000000..211b629 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/IAutoSurveyor.java @@ -0,0 +1,27 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + + +import com.bingce.coordlib.model.Coordinate; + +public interface IAutoSurveyor { + /** + * 测站坐标 + */ + Coordinate stationPoint(String originPointId); + + /** + * 测站仪器高 + */ + double instrumentHeight(); + + /** + * 目标点坐标 + */ + Coordinate targetPoint(String originPointId); + + + /** + * 角差(理论上应该所有点都一样) + */ + double angleDifference(String originPointId); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyor.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyor.java new file mode 100644 index 0000000..a37fd55 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyor.java @@ -0,0 +1,22 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +public interface ISurveyor { + + boolean isReady(); + + /** + * @param requestParam 请求参数 + */ + void requestSurveyor(RequestParam requestParam); + + void register(ISurveyorListener listener); + + void register(ISurveyorRemindListener listener); + + void unregister(ISurveyorListener listener); + + void prepareSurveyor(); + + void exitSurveyor(); + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorListener.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorListener.java new file mode 100644 index 0000000..a0aa284 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorListener.java @@ -0,0 +1,7 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +public interface ISurveyorListener { + void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd); + + void onError(String errorMsg); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorRemindListener.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorRemindListener.java new file mode 100644 index 0000000..20d50ec --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/ISurveyorRemindListener.java @@ -0,0 +1,5 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +public interface ISurveyorRemindListener { + void remindUserAimingAtWire(); +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/RequestParam.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/RequestParam.java new file mode 100644 index 0000000..ba8daae --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/RequestParam.java @@ -0,0 +1,77 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + + +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; + +public class RequestParam { + private int measureWhat; + private boolean isAlreadyRemindUserAimingAtWire; + private boolean isWellSteel; + private boolean isAloneMeasureDistancePoint; + private int measureTimes;//盘左或盘右当前第几次测量 + private int surveyorPointIndex;//当前测点在第几个 + private SurveyorPoint surveyorPoint;//当前测点 + + private IAutoSurveyor autoSurveyor; + + public RequestParam(int measureWhat, boolean isAlreadyRemindUserAimingAtWire, boolean isWellSteel, + boolean isAloneMeasureDistancePoint, int measureTimes, int surveyorPointIndex, SurveyorPoint surveyorPoint) { + this.measureWhat = measureWhat; + this.isAlreadyRemindUserAimingAtWire = isAlreadyRemindUserAimingAtWire; + this.isWellSteel = isWellSteel; + this.isAloneMeasureDistancePoint = isAloneMeasureDistancePoint; + this.measureTimes = measureTimes; + this.surveyorPointIndex = surveyorPointIndex; + this.surveyorPoint = surveyorPoint; + } + + public int getMeasureWhat() { + return measureWhat; + } + + public boolean isAlreadyRemindUserAimingAtWire() { + return isAlreadyRemindUserAimingAtWire; + } + + public boolean isWellSteel() { + return isWellSteel; + } + + public boolean isAloneMeasureDistancePoint() { + return isAloneMeasureDistancePoint; + } + + public int getMeasureTimes() { + return measureTimes; + } + + public int getSurveyorPointIndex() { + return surveyorPointIndex; + } + + public SurveyorPoint getSurveyorPoint() { + return surveyorPoint; + } + + public IAutoSurveyor getAutoSurveyor() { + return autoSurveyor; + } + + public void setAutoSurveyor(IAutoSurveyor autoSurveyor) { + this.autoSurveyor = autoSurveyor; + } + + /** + * 发送指令后是否需要超时提醒 + * + * @return + */ + public boolean isNeedOverTimeHintNot() { + if (!isAlreadyRemindUserAimingAtWire && measureTimes == 0 && + (isWellSteel || surveyorPoint.isPrismNot())) { + return true; + } + return false; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorAutoImpl.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorAutoImpl.java new file mode 100644 index 0000000..50f17c0 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorAutoImpl.java @@ -0,0 +1,202 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +import android.os.Handler; +import android.os.Looper; +import android.util.Log; + +import com.bingce.controlapphelper.datasource.database.point.PointRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.util.SurveyorTransitionUtil; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.App; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.IStationPointRecordCollect; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SpeakCache; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.util.SurveyorOpenAtrUtil; +import com.bingce.coordlib.model.Coordinate; +import com.bingce.totalstation.TotalStation; + +import net.tatans.tensorflowtts.tts.TtsManager; + + +/* + * 为方便测试和开发,抽象测量对象,执行测量操作和相应设备检测操作 + * + * */ +public class SurveyorAutoImpl extends SurveyorSingleImpl { + private final ICachedData cachedData; + private final ISurveyorData surveyorData; + private final ICycleRecorder cycleRecorder; + private final IAutoSurveyor autoSurveyor; + private final IAutoModeSwitcher autoModeSwitcher; + + private final IStationPointRecordCollect pointRecordCollect; + private int verAngleSpeakCycleIndex; + + public SurveyorAutoImpl(int measureWhat, + ICachedData cachedData, + ISurveyorData surveyorData, + IStationPointRecordCollect pointRecordCollect, + IAutoModeSwitcher autoModeSwitcher, + IAutoSurveyor autoSurveyor, + ICycleRecorder cycleRecorder) { + super(measureWhat); + this.cachedData = cachedData; + this.surveyorData = surveyorData; + this.pointRecordCollect = pointRecordCollect; + this.cycleRecorder = cycleRecorder; + this.autoModeSwitcher = autoModeSwitcher; + this.autoSurveyor = autoSurveyor; + } + + @Override + final protected void sendRequest(RequestParam requestParam, INeedOverTime needOverTime) { + if (!autoModeSwitcher.isAutoModeOpen()) { + super.sendRequest(requestParam, needOverTime); + return; + } + Log.d("hwhw", "进入自动测量sendRequest"); + //执行自动测量 + PointRecord pointRecord = pointRecordCollect.pointRecord(cycleRecorder.currentCycleIndex(), surveyorData.currentIndex()); + if (pointRecord == null) { + return; + } + + String pointId = pointRecord.getId(); + boolean openAtrPoint = SurveyorOpenAtrUtil.isOpenAtr(requestParam.getSurveyorPoint()); + if (openAtrPoint) { + requestOpenAtrPoint(requestParam, pointId, needOverTime); + } else { + //非棱镜目标或未打开atr + requestOpenAtrNot(requestParam, pointId, needOverTime); + } + } + + private void requestOpenAtrNot(RequestParam requestParam, String pointId, INeedOverTime needOverTime) { + LeftOrRight leftOrRight = surveyorData.leftOrRight(); + if (!requestParam.isAlreadyRemindUserAimingAtWire() && requestParam.getMeasureTimes() == 0) { + Log.d("hwhw", "sendRequest——旋转到大概位置"); + sendRequestRotation(leftOrRight == null || leftOrRight == LeftOrRight.left, + autoSurveyor.stationPoint(pointId), + autoSurveyor.instrumentHeight(), + autoSurveyor.targetPoint(pointId), + Double.parseDouble(requestParam.getSurveyorPoint().getPrismHeightDeal()), + autoSurveyor.angleDifference(pointId), + requestParam.getMeasureTimes(), requestParam.getSurveyorPoint()); + + needOverTime.isNeedOverTimeHint(false); + } else { + super.sendRequest(requestParam, needOverTime); + } + } + + private void requestOpenAtrPoint(RequestParam requestParam, String pointId, INeedOverTime needOverTime) { + int cycleIndex = cycleRecorder.currentCycleIndex(); + LeftOrRight leftOrRight = surveyorData.leftOrRight(); + + switch (requestParam.getMeasureWhat()) { + case StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER: + if (requestParam.getMeasureWhat() == StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT + || requestParam.getMeasureWhat() == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR) { + boolean speakSwitchCycle = SpeakCache.getInstance().isSpeakSwitchCycle(); + if (speakSwitchCycle) { + //已经播放过切换测回,当前测量不再播放测量目标,在下次播放测量目标 + SpeakCache.getInstance().removeSpeakSwitchCycle(); + } + if (requestParam.getMeasureTimes() == 0 && !speakSwitchCycle) { + boolean closePoint = cachedData.isClosePoint(0, requestParam.getSurveyorPointIndex()); + String msg; + if (closePoint) { + msg = Tools.getString(R.string.start_the_return_zero_observation); + } else { + msg = Tools.getString(R.string.start_survey_x_target, requestParam.getSurveyorPointIndex() + 1); + } + TtsManager.getInstance().speak(msg); + } + } else if (requestParam.getMeasureWhat() == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER) { + if (verAngleSpeakCycleIndex != cycleIndex) { + TtsManager.getInstance().speak("开始测量第" + (cycleIndex + 1) + "测回"); + } + verAngleSpeakCycleIndex = cycleIndex; + } + + + sendRequestDefault(leftOrRight == null || leftOrRight == LeftOrRight.left, + autoSurveyor.stationPoint(pointId), + autoSurveyor.instrumentHeight(), + autoSurveyor.targetPoint(pointId), + Double.parseDouble(requestParam.getSurveyorPoint().getPrismHeightDeal()), + autoSurveyor.angleDifference(pointId), + requestParam.getMeasureTimes(), + requestParam.getSurveyorPoint()); + + break; + case StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE: + if (surveyorData.getMeasureTimes() == 0) { + Log.d("hwhw", "sendRequest——自动测量 默认"); + sendRequestDefault(true,//盘左 + autoSurveyor.stationPoint(pointId), + autoSurveyor.instrumentHeight(), + autoSurveyor.targetPoint(pointId), + Double.parseDouble(requestParam.getSurveyorPoint().getPrismHeightDeal()), + autoSurveyor.angleDifference(pointId), + 0, + requestParam.getSurveyorPoint()); + } else { + sendRequestMeasureDistanceManualPrism(requestParam.getSurveyorPoint()); + } + break; + } + + needOverTime.isNeedOverTimeHint(true); + } + + /** + * 默认的测量方式 测角测距 自动旋转马达 + */ + private void sendRequestDefault(boolean isFace1, Coordinate station, + double hi, Coordinate target, + double hr, double angleDifference, + int times, SurveyorPoint surveyorPoint) { + delayRun(() -> { + TotalStation + .getInstance()//第三个参数是否测距 + .requestMotorMeasDist(isFace1, getRequestOpenAtr(surveyorPoint), true, App.getApp().isTwiceAiming, station, hi, angleDifference, target, hr, times, + SurveyorTransitionUtil.prismTypeToEnum(surveyorPoint), + SurveyorTransitionUtil.getPrismTypeName(surveyorPoint), + Double.parseDouble(surveyorPoint.getPrismTypeConstant())); + }); + + } + + /** + * 自动旋转到大概位置 + */ + private void sendRequestRotation(boolean isFace1, Coordinate station, + double hi, Coordinate target, + double hr, double angleDifference, + int times, SurveyorPoint surveyorPoint) { + Log.d("hwhw", "sendRequestRotation自动旋转到大概角度"); + delayRun(() -> { + TotalStation + .getInstance() + .requestMotorMeasDist(isFace1, getRequestOpenAtr(surveyorPoint), false, App.getApp().isTwiceAiming, station, hi, angleDifference, target, hr, times, + SurveyorTransitionUtil.prismTypeToEnum(surveyorPoint), + SurveyorTransitionUtil.getPrismTypeName(surveyorPoint), + Double.parseDouble(surveyorPoint.getPrismTypeConstant())); + }); + } + + private void delayRun(Runnable runnable) { + new Handler(Looper.getMainLooper()).postDelayed(runnable, 100); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMock.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMock.java new file mode 100644 index 0000000..60df8a8 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMock.java @@ -0,0 +1,176 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.util.SurveyorOpenAtrUtil; +import com.bingce.totalstation.TsException; +import com.bingce.totalstation.event.TsMeasureSdAngleEvent; + +import java.util.ArrayList; +import java.util.List; + + +public class SurveyorMock implements ISurveyor { + private ISurveyorRemindListener iSurveyorRemindListener; + private final List listenerList = new ArrayList<>(); + private boolean isSurveying = false;//标识是否下处于测量状态,等待数据返回ing + protected final ISurveyorData surveyorData; + protected final ICycleRecorder cycleRecorder; + protected final int measureWhat; + + protected SurveyorMock(int measureWhat, ISurveyorData surveyorData, ICycleRecorder cycleRecorder) { + this.measureWhat = measureWhat; + this.surveyorData = surveyorData; + this.cycleRecorder = cycleRecorder; + } + + @Override + public void register(ISurveyorListener listener) { + if (!listenerList.contains(listener)) { + listenerList.add(listener); + } + } + + @Override + public void register(ISurveyorRemindListener listener) { + this.iSurveyorRemindListener = listener; + } + + @Override + public void unregister(ISurveyorListener listener) { + listenerList.remove(listener); + } + + public void onReceive(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + synchronized (this) { + if (isSurveying) { + isSurveying = false; + for (ISurveyorListener listener : listenerList) { + if (listener == null) { + continue; + } + listener.onReceive(originalHa, originalVa, sd, clockwiseHa, topVa, hd, vd); + } + } + } + } + + /////------测试代码 + private TsMeasureSdAngleEvent test; + + private final Handler testHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(@NonNull Message msg) { + + LeftOrRight leftOrRight = surveyorData.leftOrRight(); + Log.d("hwhw", "leftOrRight=" + leftOrRight); + + TsMeasureSdAngleEvent data; + if (leftOrRight == LeftOrRight.left) { + data = TestTj.leftResult; + } else { + data = TestTj.rightResult; + } + +// TsMeasureSdAngleEvent event = com.bingce.controlapphelper.surveyor.test.Test.data(); +// if (event == null) { +// Log.d("hwhw", "TsMeasureSdAngleEvent==null"); +// } +// TsMeasureSdAngleEvent event2 = surveyorResult(event); +// if (event2.getException() != null) { +// onReceive(event2.getOriginalHa(), event2.getOriginalVa(), event2.getSd(), event2.getClockwiseHa(), event2.getTopVa(), event2.getHd(), event2.getVd()); +// } else { +// onError(event2.getException().getDescription()); +// } + onReceive(data.getOriginalHa(), data.getOriginalVa(), data.getSd(), data.getClockwiseHa(), data.getTopVa(), data.getHd(), data.getVd()); +// onReceive(0, 0, 5,0 , 0, 5, 5); + + } + }; + + public void onError(String errorMsg) { + synchronized (this) { + if (isSurveying) { + isSurveying = false; + for (ISurveyorListener listener : listenerList) { + if (listener == null) { + continue; + } + listener.onError(errorMsg); + } + } + } + } + + + protected TsMeasureSdAngleEvent surveyorResult(TsMeasureSdAngleEvent event) { + if (event == null) + return new TsMeasureSdAngleEvent(new TsException("数据为空", "")); + return event; +// if (test == null) { +// return new TsMeasureSdAngleEvent(new TsException("数据为空","")); +// } else { +// return test; +// } + } + + @Override + public boolean isReady() { + return true; + } + + @Override + public void requestSurveyor(RequestParam requestParam) { + synchronized (this) { + if (isSurveying) { + return; + } + isSurveying = true; + sendRequest(requestParam); + } + } + + @Override + public void prepareSurveyor() { + test = TestTj.data(); + } + + @Override + public void exitSurveyor() { + //清空定时 + testHandler.removeMessages(0); + isSurveying = false; + } + + protected void sendRequest(RequestParam requestParam) { + switch (requestParam.getMeasureWhat()) { + case StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT: + case StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE: + Log.d("hwhw", "发送手动测距测角指令"); + mockData(requestParam); + break; +// case StateConstants.VALUE_MEASURE_WHAT_ANGLE: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER: + Log.d("hwhw", "发送手动仅测角指令"); + mockData(requestParam); + break; + } + } + + protected void mockData(RequestParam requestParam) { + boolean openAtr = SurveyorOpenAtrUtil.isOpenAtr(requestParam.getSurveyorPoint()); + Log.d("hwhw", "SurveyorPoint_openAtr=" + openAtr); + testHandler.sendEmptyMessageDelayed(0, 500); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMockAuto.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMockAuto.java new file mode 100644 index 0000000..662e29f --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorMockAuto.java @@ -0,0 +1,268 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +import android.util.Log; + +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.event.SurveyStateEvent; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.data.SpeakCache; +import com.bingce.controlnetwork.surveyor.state.IAutoModeSwitcher; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.surveyor.state.StateType; +import com.bingce.controlnetwork.surveyor.state.base.AbstructStateManager; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.controlnetwork.util.SurveyorOpenAtrUtil; +import com.bingce.totalstation.event.TsMeasureSdAngleEvent; +import com.bingce.utils.Util; + +import net.tatans.tensorflowtts.tts.TtsManager; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + + +public class SurveyorMockAuto extends SurveyorMock { + private static final double startHorAngle = 10.2536f; + private static final double startDistance = 1.732f; + private final String stationId; + private final ICachedData cachedData; + private IAutoModeSwitcher autoModeSwitcher; + private AbstructStateManager stateManager; + private final Map key2MeasuredSdAngle = new HashMap<>(); + + private final Map _3MeasuredSdAngle = new HashMap<>(); + + private final Map _3MeasuredSdAngleWithError = new HashMap<>(); + + public SurveyorMockAuto(int measureWhat, String stationId, boolean autoClosed, int cycleCount, + ICachedData cachedData, + ISurveyorData surveyorData, + ICycleRecorder cycleRecorder, + IAutoModeSwitcher autoModeSwitcher, + AbstructStateManager stateManager) { + super(measureWhat, surveyorData, cycleRecorder); + this.stationId = stationId; + this.cachedData = cachedData; + this.autoModeSwitcher = autoModeSwitcher; + this.stateManager = stateManager; + //初始化测量数据----自动测量 + double startHorRadian = Util.dmsDoubleToRadian(startHorAngle); + double offsetVerRadian = Util.dmsDoubleToRadian(0); + double distance = startDistance; + double one = Util.dmsDoubleToRadian(1); + int originCount = cachedData.pointCount() - (autoClosed ? 1 : 0); + + for (int itemIndex = 0; itemIndex < originCount; itemIndex++) { + double horOffset = (new Random()).nextInt(36) * one; + double verOffset = -(new Random()).nextInt(9) * one; + offsetVerRadian += verOffset; + + startHorRadian += horOffset; + distance += (new Random()).nextInt(3); + + setupSdAngle(stationId, cycleCount, itemIndex, startHorRadian, offsetVerRadian, distance, + cachedData, key2MeasuredSdAngle); + + if (autoClosed && 0 == itemIndex) { + setupSdAngle(stationId, cycleCount, originCount, startHorRadian, offsetVerRadian, distance, + cachedData, key2MeasuredSdAngle); + } + } + + //初始化固定数据---3 + setupSdAngle(_3MeasuredSdAngle, 0, LeftOrRight.left, 0.41371, 92.1354, 32.424); + setupSdAngle(_3MeasuredSdAngle, 0, LeftOrRight.right, 180.41327, 267.46045, 32.424); + + setupSdAngle(_3MeasuredSdAngle, 1, LeftOrRight.left, 1.32259, 91.25539, 37.741); + setupSdAngle(_3MeasuredSdAngle, 1, LeftOrRight.right, 181.32221, 268.34029, 37.741); + + setupSdAngle(_3MeasuredSdAngle, 2, LeftOrRight.left, 15.26574, 92.08163, 35.865); + setupSdAngle(_3MeasuredSdAngle, 2, LeftOrRight.right, 195.26555, 267.51424, 35.865); + + //初始化固定数据---3-error + setupSdAngle(_3MeasuredSdAngleWithError, 0, LeftOrRight.left, 1.32259, 91.25539, 37.741); + setupSdAngle(_3MeasuredSdAngleWithError, 0, LeftOrRight.right, 181.32221, 268.34029, 37.741); + + setupSdAngle(_3MeasuredSdAngleWithError, 1, LeftOrRight.left, 1.32259, 91.25539, 37.741); + setupSdAngle(_3MeasuredSdAngleWithError, 1, LeftOrRight.right, 181.32221, 268.34029, 37.741); + + setupSdAngle(_3MeasuredSdAngleWithError, 2, LeftOrRight.left, 15.26574, 92.08163, 35.865); + setupSdAngle(_3MeasuredSdAngleWithError, 2, LeftOrRight.right, 195.26555, 267.51424, 35.865); + } + + private static void setupSdAngle(String stationId, int cycleCount, int itemIndex, + double startHorRadian, + double offsetVerRadian, + double distance, + ICachedData cachedData, + final Map key2MeasuredSdAngle) { + for (int cycleIndex = 0; cycleIndex < cycleCount; cycleIndex++) { + String pointId = cachedData.pointId(cycleIndex, itemIndex); + + String leftKey = IdUtil.surveyorRecordKey( + stationId, + cycleIndex, + pointId, + LeftOrRight.left); + key2MeasuredSdAngle.put( + leftKey, + measureSdAngleEvent(startHorRadian, Math.PI / 2 + offsetVerRadian, distance)); + + String rightKey = IdUtil.surveyorRecordKey( + stationId, + cycleIndex, + pointId, + LeftOrRight.right); + key2MeasuredSdAngle.put( + rightKey, + measureSdAngleEvent(startHorRadian + Math.PI, 3 * Math.PI / 2 - offsetVerRadian, distance)); + } + } + + private static String keyOf(int itemIndex, LeftOrRight leftOrRight) { + return "_" + itemIndex + "_" + leftOrRight.name(); + } + + private static void setupSdAngle(Map key2MeasuredSdAngle, int itemIndex, LeftOrRight leftOrRight, + double hAngle, double vAngle, double distance) { + + String key = keyOf(itemIndex, leftOrRight); + key2MeasuredSdAngle.put( + key, + measureSdAngleEvent( + Util.dmsDoubleToRadian(hAngle), + Util.dmsDoubleToRadian(vAngle), + distance)); + } + + private static TsMeasureSdAngleEvent measureSdAngleEvent(double hAngle, double vAngle, double distance) { + double hd = Math.abs(distance * Math.sin(vAngle)); + double vd = distance * Math.cos(vAngle); + + return new TsMeasureSdAngleEvent(hAngle, vAngle, distance, hAngle, vAngle, hd, vd); + } + +// @Override +// protected TsMeasureSdAngleEvent surveyorResult() { +// TsMeasureSdAngleEvent event = super.surveyorResult(); +// if (event.getException() != null) { +// if (Test.TYPE_AUTO.equals(event.getException().getDescription())) { +// int cycleIndex = cycleRecorder.currentCycleIndex(); +// int itemIndex = surveyorData.currentIndex(); +// String pointId = cachedData.pointId(cycleIndex, itemIndex); +// String key = IdUtil.surveyorRecordKey( +// stationId, +// cycleIndex, +// pointId, +// surveyorData.leftOrRight()); +// +// return key2MeasuredSdAngle.get(key); +// } else if (Test.TYPE_AUTO_WITH_RANDOM.equals(event.getException().getDescription())) { +// int cycleIndex = cycleRecorder.currentCycleIndex(); +// int itemIndex = surveyorData.currentIndex(); +// String pointId = cachedData.pointId(cycleIndex, itemIndex); +// String key = IdUtil.surveyorRecordKey( +// stationId, +// cycleIndex, +// pointId, +// surveyorData.leftOrRight()); +// TsMeasureSdAngleEvent sdAngleEvent = key2MeasuredSdAngle.get(key); +// if (sdAngleEvent == null) { +// return null; +// } +// +// double one = Util.dmsDoubleToRadian(1); +// double hAngle = sdAngleEvent.getOriginalHa(); +// double vAngle = sdAngleEvent.getOriginalVa(); +// double distance = sdAngleEvent.getSd(); +// double ha = hAngle + ((new Random()).nextInt(5) - 5) * 0.0001 * one; +// double va = vAngle + ((new Random()).nextInt(5) - 5) * 0.0001 * one; +// double sd = distance + ((new Random()).nextInt(5) - 5) * 0.001; +// double hd = Math.abs(sd * Math.sin(va)); +// double vd = sd * Math.cos(va); +// +// return new TsMeasureSdAngleEvent(ha, va, sd, ha, va, hd, vd); +// } else if (Test.TYPE_AUTO_WITH_3.equals(event.getException().getDescription())) { +// int itemIndex = surveyorData.currentIndex(); +// LeftOrRight leftOrRight = surveyorData.leftOrRight(); +// String key = keyOf(itemIndex, leftOrRight); +// return _3MeasuredSdAngle.get(key); +// } else if (Test.TYPE_AUTO_WITH_3_ERROR.equals(event.getException().getDescription())) { +// int itemIndex = surveyorData.currentIndex(); +// LeftOrRight leftOrRight = surveyorData.leftOrRight(); +// String key = keyOf(itemIndex, leftOrRight); +// return _3MeasuredSdAngleWithError.get(key); +// } else if (Test.TYPE_VALUE_180_267_32.equals(event.getException().getDescription())) { +// return measureSdAngleEvent(Util.dmsDoubleToRadian(180.41327), Util.dmsDoubleToRadian(267.46045), 32.424); +// } else if (Test.TYPE_ERROR_BUSY.equals(event.getException().getDescription())) { +// return new TsMeasureSdAngleEvent(new TsException("仪器繁忙,请稍后重试", 1)); +// } +// } +// return super.surveyorResult(); +// } + + @Override + final protected void sendRequest(RequestParam requestParam) { + if (!autoModeSwitcher.isAutoModeOpen()) { + super.sendRequest(requestParam); + return; + } + Log.d("hwhw", "进入自动测量sendRequest"); + //执行自动测量 + boolean openAtr = SurveyorOpenAtrUtil.isOpenAtr(requestParam.getSurveyorPoint()); + Log.d("hwhw", "SurveyorPoint_openAtr=" + openAtr); + if (openAtr) { + requestOpenAtr(requestParam); + } else { + requestOpenArtNot(requestParam); + } + } + + private void requestOpenArtNot(RequestParam requestParam) { + if (!requestParam.isAlreadyRemindUserAimingAtWire() && requestParam.getMeasureTimes() == 0) { + Log.d("hwhw", "sendRequest——旋转到大概位置"); + SurveyStateEvent.postIdle(); + exitSurveyor(); + stateManager.enter(StateType.doWellMeasureRotationReady); + } else { + Log.d("hwhw", "自动测量——super.sendRequest(requestParam)"); + super.sendRequest(requestParam); + } + } + + private void requestOpenAtr(RequestParam requestParam) { + switch (requestParam.getMeasureWhat()) { + case StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT: +// case StateConstants.VALUE_MEASURE_WHAT_ANGLE: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER: + Log.d("hwhw", "sendRequest——自动测量 驱动马达测角测距"); + boolean speakSwitchCycle = SpeakCache.getInstance().isSpeakSwitchCycle(); + if (speakSwitchCycle) { + //已经播放过切换测回,当前测量不再播放测量目标,在下次播放测量目标 + SpeakCache.getInstance().removeSpeakSwitchCycle(); + } + if (requestParam.getMeasureTimes() == 0 && !speakSwitchCycle) { + boolean closePoint = cachedData.isClosePoint(0, requestParam.getSurveyorPointIndex()); + String msg; + if (closePoint) { + msg = Tools.getString(R.string.start_the_return_zero_observation); + } else { + msg = Tools.getString(R.string.start_survey_x_target, requestParam.getSurveyorPointIndex() + 1); + } + TtsManager.getInstance().speak(msg); + } + mockData(requestParam); + break; + case StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE: + Log.d("hwhw", "sendRequest——自动测量 仅测距 调用手动测角测距指令"); + mockData(requestParam); + break; + } + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorSingleImpl.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorSingleImpl.java new file mode 100644 index 0000000..bef0bf1 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/SurveyorSingleImpl.java @@ -0,0 +1,258 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.util.SurveyorTransitionUtil; +import com.bingce.controlnetwork.surveyor.state.StateConstantsTj; +import com.bingce.controlnetwork.util.SurveyorOpenAtrUtil; +import com.bingce.device.Device; +import com.bingce.device.enums.DeviceTypeEnum; +import com.bingce.totalstation.TotalStation; +import com.bingce.totalstation.TsListener; + +import java.util.ArrayList; +import java.util.List; + +/* + * 为方便测试和开发,抽象测量对象,执行测量操作和相应设备检测操作 + * + * */ +public class SurveyorSingleImpl implements ISurveyor, TsListener.MeasSdAnglesListener, TsListener.ReadAnglesListener, TsListener.AutoPositionListener { + private ISurveyorRemindListener iSurveyorRemindListener; + private final List listenerList = new ArrayList<>(); + private boolean isSurveying = false;//标识是否下处于测量状态,等待数据返回ing + private final int MSG_DELAY_TIME_WHAT = 100;//msg.what + private static final long DELAY_TIME = 20000; + + protected final int measureWhat; + + + private final Handler mainHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(@NonNull Message msg) { + if (msg.what == MSG_DELAY_TIME_WHAT) { + onMeasSdAnglesFailed("测量超时请检查目标", ""); + } + } + }; + + public SurveyorSingleImpl(int measureWhat) { + this.measureWhat = measureWhat; + } + + @Override + public void register(ISurveyorListener listener) { + if (!listenerList.contains(listener)) { + listenerList.add(listener); + } + } + + @Override + public void register(ISurveyorRemindListener listener) { + this.iSurveyorRemindListener = listener; + } + + @Override + public void unregister(ISurveyorListener listener) { + listenerList.remove(listener); + } + + protected void onReceiveData(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + for (ISurveyorListener listener : listenerList) { + if (listener == null) { + continue; + } + listener.onReceive(originalHa, originalVa, sd, clockwiseHa, topVa, hd, vd); + } + } + + @Override + public boolean isReady() { + return isConnect(); + } + + private static boolean isConnect() { + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_RTK) { + return false; + } + return Device.getInstance().isDeviceConnected(); + } + + protected void sendRequest(RequestParam requestParam, INeedOverTime needOverTime) { + switch (requestParam.getMeasureWhat()) { + case StateConstantsTj.VALUE_MEASURE_WHAT_DEFAULT: + if (requestParam.getSurveyorPoint().isWellSteel()) { + sendRequestOnlyMeasureAngle(requestParam.getSurveyorPoint()); + } else { + sendRequestMeasureDistanceManualPrism(requestParam.getSurveyorPoint()); + } + break; + case StateConstantsTj.VALUE_MEASURE_WHAT_DISTANCE: + sendRequestMeasureDistanceManualPrism(requestParam.getSurveyorPoint()); + break; +// case StateConstants.VALUE_MEASURE_WHAT_ANGLE: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_HOR: + case StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER: + sendRequestOnlyMeasureAngle(requestParam.getSurveyorPoint()); + break; + } + needOverTime.isNeedOverTimeHint(true); + } + + /** + * 仅测角 + * + * @param surveyorPoint + */ + protected void sendRequestOnlyMeasureAngle(SurveyorPoint surveyorPoint) { + Log.d("hwhw", " TotalStation.getInstance().requestAngles()调用"); + TotalStation.getInstance().requestAngles(); + } + + + /** + * 手动测距 + * + * @param surveyorPoint + */ + protected void sendRequestMeasureDistanceManualPrism(SurveyorPoint surveyorPoint) { + Log.d("hwhw", " TotalStation.getInstance().requestMeasDistExact()调用"); + TotalStation.getInstance().requestMeasSdAnglesExact(getRequestOpenAtr(surveyorPoint), SurveyorTransitionUtil.prismTypeToEnum(surveyorPoint), + SurveyorTransitionUtil.getPrismTypeName(surveyorPoint), Double.parseDouble(surveyorPoint.getPrismTypeConstantDeal())); + } + + @Override + public void requestSurveyor(RequestParam requestParam) { + synchronized (this) { + if (isSurveying) { + return; + } + isSurveying = true; + //调用全站仪执行测量指令 + sendRequest(requestParam, need -> { + if (need) { + //超时提醒 + mainHandler.sendEmptyMessageDelayed(MSG_DELAY_TIME_WHAT, DELAY_TIME); + } + }); + } + } + + @Override + public void prepareSurveyor() { + Log.d("hwhw", "prepareSurveyor"); + TsListener.getInstance().addMeasSdAnglesListener(this); + TsListener.getInstance().addReadAnglesListener(this); + TsListener.getInstance().addAutoPositionListener(this); + } + + @Override + public void exitSurveyor() { + Log.d("hwhw", "exitSurveyor"); + + TsListener.getInstance().removeMeasSdAnglesListener(this); + TsListener.getInstance().removeAutoPositionListener(this); + TsListener.getInstance().removeReadAnglesListener(this); + + removeDelayTimeWhat(); + //清空标识 + isSurveying = false; + } + + /** + * 清空定时 + */ + private void removeDelayTimeWhat() { + Log.d("hwhw", "removeDelayTimeWhat"); + mainHandler.removeMessages(MSG_DELAY_TIME_WHAT); + } + + @Override + public void onPositionDoneSuccess() { + synchronized (this) { + //提醒用户人工瞄准 + if (iSurveyorRemindListener != null) { + iSurveyorRemindListener.remindUserAimingAtWire(); + } + } + } + + @Override + public void onPositionFailed(String errorMsg, String original) { + for (ISurveyorListener listener : listenerList) { + if (listener == null) { + continue; + } + listener.onError(errorMsg); + } + } + + @Override + public void onMeasSdAnglesSuccess(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + Log.d("hwhw", "onMeasSdAngleSuccess"); + dealSurveyorSuccess(originalHa, originalVa, sd, clockwiseHa, topVa, hd, vd); + } + + @Override + public void onMeasSdAnglesFailed(String errorMsg, String original) { + Log.d("hwhw", "onMeasSdAngleFailed"); + dealSuveyorError(errorMsg); + } + + @Override + public void onReadAnglesSuccess(double originalHa, double originalVa, double clockwiseHa, double topVa) { + Log.d("hwhw", "onReadAngleSuccess"); + + double hd = Math.abs(100 * Math.sin(topVa)); + double vd = 100 * Math.cos(topVa); + //sd hd vd 重新赋值 + dealSurveyorSuccess(originalHa, originalVa, 100, clockwiseHa, topVa, hd, vd); + } + + @Override + public void onReadAnglesFailed(String errorMsg, String original) { + Log.d("hwhw", "onReadAngleFailed"); + + dealSuveyorError(errorMsg); + } + + + interface INeedOverTime { + void isNeedOverTimeHint(boolean need); + } + + private void dealSuveyorError(String errorMsg) { + //清空超时的提示 + removeDelayTimeWhat(); + isSurveying = false; + for (ISurveyorListener listener : listenerList) { + if (listener == null) { + continue; + } + listener.onError(errorMsg); + } + } + + private void dealSurveyorSuccess(double originalHa, double originalVa, double sd, double clockwiseHa, double topVa, double hd, double vd) { + synchronized (this) { + //清空超时的提示 + removeDelayTimeWhat(); + //传递数据 + if (isSurveying) { + isSurveying = false; + onReceiveData(originalHa, originalVa, sd, clockwiseHa, topVa, hd, vd); + } + } + } + + protected boolean getRequestOpenAtr(SurveyorPoint surveyorPoint) { + return SurveyorOpenAtrUtil.isOpenAtr(surveyorPoint); + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectFragment.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectFragment.java index c8f1a2b..44e96c0 100644 --- a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectFragment.java +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectFragment.java @@ -14,13 +14,10 @@ import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; -import com.bingce.controlapphelper.surveyor.test.Test; - -import org.jetbrains.annotations.NotNull; - import com.bingce.controlnetwork.R; import com.bingce.controlnetwork.adapter.IndexWithTextAdapter; -import com.bingce.controlnetwork.adapter.IndexWithTextAdapter; + +import org.jetbrains.annotations.NotNull; public class TestDataSelectFragment extends DialogFragment { @@ -57,10 +54,10 @@ public class TestDataSelectFragment extends DialogFragment { } protected void refreshRecyclerView(RecyclerView recyclerView) { - IndexWithTextAdapter adapter = new IndexWithTextAdapter<>(Test.items, new IndexWithTextAdapter.IOnItemClick() { + IndexWithTextAdapter adapter = new IndexWithTextAdapter<>(TestTj.items, new IndexWithTextAdapter.IOnItemClick() { @Override - public void onItemClick(Test.Item item) { - Test.type = item; + public void onItemClick(TestTj.Item item) { + TestTj.type = item; dismiss(); } }); diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectLevelFragment.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectLevelFragment.java new file mode 100644 index 0000000..428a1b8 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestDataSelectLevelFragment.java @@ -0,0 +1,136 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.func.level.sendreceive.TestData; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + + +public class TestDataSelectLevelFragment extends DialogFragment { + private static IClickItem clickItem; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_single_list_layout, container, false); + + // Set the adapter + if (view instanceof RecyclerView) { + RecyclerView recyclerView = (RecyclerView) view; + refreshRecyclerView(recyclerView); + } + + return view; + } + + @Override + public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Dialog dialog = getDialog(); + if (dialog == null) { + return; + } + Window window = dialog.getWindow(); + if (window == null) { + return; + } + window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); + WindowManager.LayoutParams lps = window.getAttributes(); + lps.verticalMargin = 0.4F; + lps.horizontalMargin = 0.4F; + window.setAttributes(lps); + } + + protected void refreshRecyclerView(RecyclerView recyclerView) { + List list = TestData.Companion.getTextShowList(); + recyclerView.setAdapter(new MyAdapter(list)); + } + + public static void show(FragmentManager fragmentManager, IClickItem clickItem) { + TestDataSelectLevelFragment.clickItem = clickItem; + TestDataSelectLevelFragment fragment = new TestDataSelectLevelFragment(); + fragment.show(fragmentManager, TestDataSelectLevelFragment.class.getName()); + } + + private class MyAdapter extends RecyclerView.Adapter { + + private final List data; + + public MyAdapter(List data) { + this.data = data; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate the custom layout + View itemView = inflater.inflate(R.layout.list_item_index_text_layout, parent, false); + + // Return a new holder instance + return new ViewHolder(itemView); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + // Get the data model based on position + String item = data.get(position); + + // Set item views based on your views and data model + holder.index.setText(String.valueOf(position + 1)); + holder.text.setText(item); + + holder.itemView.setOnClickListener(v -> { + if (clickItem != null) { + clickItem.click(holder.getBindingAdapterPosition()); + + dismissAllowingStateLoss(); + } + + }); + } + + @Override + public int getItemCount() { + return data.size(); + } + + // Provide a reference to the views for each data item + + } + + private static class ViewHolder extends RecyclerView.ViewHolder { + public TextView index; + public TextView text; + + public ViewHolder(View itemView) { + super(itemView); + index = itemView.findViewById(R.id.index); + text = itemView.findViewById(R.id.text); + } + } + + public interface IClickItem { + void click(int position); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestTj.java b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestTj.java new file mode 100644 index 0000000..20fffc7 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/surveyor/surveyor/TestTj.java @@ -0,0 +1,180 @@ +package com.bingce.controlnetwork.surveyor.surveyor; + +import com.bingce.controlapphelper.BuildConfig; +import com.bingce.controlapphelper.model.UniversalListItem; +import com.bingce.controlapphelper.model.ViewItemType; +import com.bingce.totalstation.event.TsMeasureSdAngleEvent; +import com.bingce.utils.Util; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class TestTj { + public static boolean DEBUG = BuildConfig.DEBUG && false; + public final static String TYPE_ERROR = "__TYPE_ERROR__"; + public final static String TYPE_ERROR_BUSY = "__TYPE_ERROR BUSY__"; + public final static String TYPE_AUTO = "___TYPE__AUTO___"; + public final static String TYPE_VALUE_180_267_32 = "180.41327 -- 267.46045 ---32.424"; + public final static String TYPE_AUTO_WITH_RANDOM = "___TYPE_AUTO_RANDOM"; + public final static String TYPE_AUTO_WITH_3 = "___TYPE_AUTO_3"; + public final static String TYPE_AUTO_WITH_3_ERROR = "___TYPE_AUTO_3_ERROR"; + + private static final double startHorAngle = 10.2536f; + private static final double startDistance = 1.732f; + public static final TsMeasureSdAngleEvent leftResult = new TsMeasureSdAngleEvent(Util.dmsDoubleToRadian(30), Util.dmsDoubleToRadian(60), 5, 0, 0, 5, 5); + public static final TsMeasureSdAngleEvent rightResult = new TsMeasureSdAngleEvent(Util.dmsDoubleToRadian(150), Util.dmsDoubleToRadian(300), 5, 0, 0, 5, 5); + + public final static List items = new ArrayList<>(); + + static { + items.add(new Item("测量失败", TYPE_ERROR, 0, 0, 0)); + items.add(new Item("仪器繁忙", TYPE_ERROR_BUSY, 0, 0, 0)); + items.add(new Item("180.41327 -- 267.46045 ---32.424", TYPE_VALUE_180_267_32, 0, 0, 0)); + items.add(new Item("自动测量", TYPE_AUTO, 0, 0, 0)); + items.add(new Item("自动测量+随机值", TYPE_AUTO_WITH_RANDOM, 0, 0, 0)); + items.add(new Item("自动测量+3固定值", TYPE_AUTO_WITH_3, 0, 0, 0)); + items.add(new Item("自动测量+3+第一个error", TYPE_AUTO_WITH_3_ERROR, 0, 0, 0)); + double startHorRadian = Util.dmsDoubleToRadian(startHorAngle); + double offsetVerRadian = Util.dmsDoubleToRadian(0); + double distance = startDistance; + + double one = Util.dmsDoubleToRadian(1); + for (int i = 0; i < 10; i++) { + double horOffset = (new Random()).nextInt(36) * one; + double verOffset = -(new Random()).nextInt(9) * one; + offsetVerRadian += verOffset; + + startHorRadian += horOffset; + distance += (new Random()).nextInt(3); + + String leftName = "左:" + + Util.radianToDmsString(startHorRadian, 1) + + " - " + + Util.radianToDmsString(Math.PI / 2 + offsetVerRadian, 1) + + " - " + + Util.formatDouble2String(distance, 3); + items.add(new Item(leftName, leftName, + startHorRadian, + Math.PI / 2 + offsetVerRadian, + distance)); + + double rightHorRadian = startHorRadian + Math.PI; + double rightVerRadian = 3 * Math.PI / 2 - offsetVerRadian; + double rightDistance = distance; + + String rightName = "右:" + + Util.radianToDmsString(rightHorRadian, 1) + + " - " + + Util.radianToDmsString(rightVerRadian, 1) + + " - " + + Util.formatDouble2String(rightDistance, 3); + items.add(new Item(rightName, rightName, + rightHorRadian, + rightVerRadian, + rightDistance)); + } + } + + + public static Item type = items.get(1); + + public static TsMeasureSdAngleEvent data() { + double one = Util.dmsDoubleToRadian(1); + double ha = type.horAngle() + ((new Random()).nextInt(5) - 5) * 0.0001 * one; + double va = type.verAngle() + ((new Random()).nextInt(5) - 5) * 0.0001 * one; + double sd = type.distance() + ((new Random()).nextInt(5) - 5) * 0.001; + double hd = Math.abs(sd * Math.sin(va)); + double vd = sd * Math.cos(va); + switch (type.getId()) { + case TYPE_ERROR: + return data(error()).get(0); + case TYPE_AUTO: + return data(auto()).get(0); + case TYPE_AUTO_WITH_RANDOM: + return data(autoWithRandom()).get(0); + case TYPE_AUTO_WITH_3: + return data(autoWith3()).get(0); + case TYPE_AUTO_WITH_3_ERROR: + return data(autoWith3With1Error()).get(0); + case TYPE_VALUE_180_267_32: + return data(rightData()).get(0); + case TYPE_ERROR_BUSY: + return data(busy()).get(0); + default: { + return new TsMeasureSdAngleEvent(ha, va, sd, ha, va, hd, vd); + } + } + } + + private static List data(String data) { + Gson gson = new Gson(); + return gson.fromJson(data, new TypeToken>() { + }.getType()); + } + + private static String error() { + return "[{\"exception\":{\"description\":\"测量失败~~~\"}}]"; + } + + private static String busy() { + return "[{\"exception\":{\"description\":\"" + TYPE_ERROR_BUSY + "\"}}]"; + } + + private static String auto() { + return "[{\"exception\":{\"description\":\"" + TYPE_AUTO + "\"}}]"; + } + + private static String autoWithRandom() { + return "[{\"exception\":{\"description\":\"" + TYPE_AUTO_WITH_RANDOM + "\"}}]"; + } + + private static String autoWith3() { + return "[{\"exception\":{\"description\":\"" + TYPE_AUTO_WITH_3 + "\"}}]"; + } + + private static String autoWith3With1Error() { + return "[{\"exception\":{\"description\":\"" + TYPE_AUTO_WITH_3_ERROR + "\"}}]"; + } + + private static String rightData() { + return "[{\"exception\":{\"description\":\"" + TYPE_VALUE_180_267_32 + "\"}}]"; + } + + public static class Item extends UniversalListItem { + public Item(String name, String id, double horAngle, double verAngle, double distance) { + super(name, id, new V(horAngle, verAngle, distance)); + } + + @Override + public ViewItemType getType() { + return ViewItemType.indexWithName; + } + + public double horAngle() { + return getValue().horAngle; + } + + public double verAngle() { + return getValue().verAngle; + } + + public double distance() { + return getValue().distance; + } + } + + private static class V { + public final double horAngle; + public final double verAngle; + public final double distance; + + public V(double horAngle, double verAngle, double distance) { + this.horAngle = horAngle; + this.verAngle = verAngle; + this.distance = distance; + } + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/ui/vh/AbstractSurveyorDataViewHolder.java b/app/src/main/java/com/bingce/controlnetwork/ui/vh/AbstractSurveyorDataViewHolder.java new file mode 100644 index 0000000..16b3514 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/ui/vh/AbstractSurveyorDataViewHolder.java @@ -0,0 +1,107 @@ +package com.bingce.controlnetwork.ui.vh; + +import android.content.Context; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; + +public abstract class AbstractSurveyorDataViewHolder extends RecyclerView.ViewHolder { + protected final Context context; + protected final TextView leftLabel; + protected final TextView rightLabel; + + protected final TextView pointName; + protected final TextView heightValue; + protected final TextView prismValue; + + protected final TextView leftAngleHor1; + protected final TextView leftAngleHor2; + protected final TextView leftAngleVer1; + protected final TextView leftAngleVer2; + protected final TextView leftDistance1; + protected final TextView leftDistance2; + + protected final TextView rightAngleHor1; + protected final TextView rightAngleHor2; + protected final TextView rightAngleVer1; + protected final TextView rightAngleVer2; + protected final TextView rightDistance1; + protected final TextView rightDistance2; + + protected final TextView averageHorAngle; + protected final TextView averageVerAngle; + protected final TextView averageDistance; + + protected final View selectMask; + + protected final TextView _2c; + protected final TextView _i; + protected final TextView _2d; + + protected final TextView distanceTitle; + protected View itemView; + + protected static final int TYPE_LEFT1 = 1; + protected static final int TYPE_LEFT2 = 2; + protected static final int TYPE_RIGHT1 = 3; + protected static final int TYPE_RIGHT2 = 4; + protected static final String ORIGINAL_VALUE = "-"; + protected static final String SKIP_VALUE = "*"; + + public AbstractSurveyorDataViewHolder(Context context, @NonNull View itemView) { + super(itemView); + this.context = context; + leftLabel = itemView.findViewById(R.id.left_label); + rightLabel = itemView.findViewById(R.id.right_label); + + pointName = itemView.findViewById(R.id.pointName); + heightValue = itemView.findViewById(R.id.height_value); + prismValue = itemView.findViewById(R.id.prism_value); + + leftAngleHor1 = itemView.findViewById(R.id.left_angle_hor_1); + leftAngleHor2 = itemView.findViewById(R.id.left_angle_hor_2); + leftAngleVer1 = itemView.findViewById(R.id.left_angle_ver_1); + leftAngleVer2 = itemView.findViewById(R.id.left_angle_ver_2); + leftDistance1 = itemView.findViewById(R.id.left_distance_1); + leftDistance2 = itemView.findViewById(R.id.left_distance_2); + + rightAngleHor1 = itemView.findViewById(R.id.right_angle_hor_1); + rightAngleHor2 = itemView.findViewById(R.id.right_angle_hor_2); + rightAngleVer1 = itemView.findViewById(R.id.right_angle_ver_1); + rightAngleVer2 = itemView.findViewById(R.id.right_angle_ver_2); + rightDistance1 = itemView.findViewById(R.id.right_distance_1); + rightDistance2 = itemView.findViewById(R.id.right_distance_2); + + averageHorAngle = itemView.findViewById(R.id.average_angle_hor); + averageVerAngle = itemView.findViewById(R.id.average_angle_ver); + averageDistance = itemView.findViewById(R.id.average_distance); + + selectMask = itemView.findViewById(R.id.mask); + + _2c = itemView.findViewById(R.id.value_2c); + _i = itemView.findViewById(R.id.value_i); + _2d = itemView.findViewById(R.id.value_2d); + + distanceTitle = itemView.findViewById(R.id.distance_title); + this.itemView = itemView; + } + + public abstract void setup(int itemIndex, + String stationId, + boolean showSlopDistance, + ICachedData cachedData, + ICycleRecorder cycleRecorder, + ISurveyorData surveyorData); + + protected boolean isCurrentItem(int itemIndexAdapter, int compareIndex) { + return itemIndexAdapter == compareIndex; + } + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/ui/vh/StationAdjustAloneDistanceViewHolder.java b/app/src/main/java/com/bingce/controlnetwork/ui/vh/StationAdjustAloneDistanceViewHolder.java new file mode 100644 index 0000000..ff5faf5 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/ui/vh/StationAdjustAloneDistanceViewHolder.java @@ -0,0 +1,21 @@ +package com.bingce.controlnetwork.ui.vh; + +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlnetwork.R; + + +public class StationAdjustAloneDistanceViewHolder extends RecyclerView.ViewHolder { + public final TextView pointName; + public final TextView distance; + + public StationAdjustAloneDistanceViewHolder(@NonNull View itemView) { + super(itemView); + pointName = itemView.findViewById(R.id.point_name); + distance = itemView.findViewById(R.id.distance); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataAloneDistanceViewHolder.java b/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataAloneDistanceViewHolder.java index 2b3524a..0b4277c 100644 --- a/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataAloneDistanceViewHolder.java +++ b/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataAloneDistanceViewHolder.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.alonedistance.WellDistance; import com.bingce.controlapphelper.model.LeftOrRight; import com.bingce.controlapphelper.surveyor.data.CachedDataAloneDistance; import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; @@ -113,7 +114,7 @@ public class SurveyorDataAloneDistanceViewHolder extends RecyclerView.ViewHolder //先清空下realDistanceValues保证数据不错乱,注意位置在前面 clearRealDistanceValues(); - List distanceDatas = getDistanceDataFromCacheData(cachedData, stationId, currentCycleIndex, itemIndex); + List distanceDatas = getDistanceDataFromCacheData(cachedData, stationId, currentCycleIndex, itemIndex); setDistanceViewData(distanceDatas, currentSurveyorIndex == itemIndex); //设置中值和2d @@ -144,8 +145,8 @@ public class SurveyorDataAloneDistanceViewHolder extends RecyclerView.ViewHolder * @param itemIndex * @return */ - private List getDistanceDataFromCacheData(CachedDataAloneDistance cachedData, String stationId, int currentCycleIndex, int itemIndex) { - List distanceValues = null; + private List getDistanceDataFromCacheData(CachedDataAloneDistance cachedData, String stationId, int currentCycleIndex, int itemIndex) { + List distanceValues = null; String pointId = cachedData.pointId(currentCycleIndex, itemIndex); String recordId = IdUtil.createSurveyorRecordId(stationId, currentCycleIndex, pointId, LeftOrRight.left); AloneDistanceRecord aloneDistanceRecord = cachedData.getAloneDistanceRecord(recordId); @@ -222,15 +223,15 @@ public class SurveyorDataAloneDistanceViewHolder extends RecyclerView.ViewHolder * @param aloneDistanceValues * @param isSelected */ - private void setDistanceViewData(List aloneDistanceValues, boolean isSelected) { + private void setDistanceViewData(List aloneDistanceValues, boolean isSelected) { if (aloneDistanceValues == null) return; for (int i = 0; i < aloneDistanceValues.size(); i++) { - Double aDouble = aloneDistanceValues.get(i); + WellDistance aDouble = aloneDistanceValues.get(i); TextView textView = distanceViews.get(i); - setDistance(textView, aDouble); + setDistance(textView, aDouble.hovDistance); setTextColor(textView, isSelected ? R.color.value_1_selected : R.color.value_1_normal); //存一下 - realDistanceValues.add(aDouble); + realDistanceValues.add(aDouble.hovDistance); } } diff --git a/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataViewHolder.java b/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataViewHolder.java index 744c8f8..1eccc33 100644 --- a/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataViewHolder.java +++ b/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataViewHolder.java @@ -5,100 +5,33 @@ import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; import com.bingce.controlapphelper.model.DataCategory; import com.bingce.controlapphelper.model.LeftOrRight; -import com.bingce.controlapphelper.surveyor.data.ICachedData; -import com.bingce.controlapphelper.surveyor.data.ICycleRecorder; -import com.bingce.controlapphelper.surveyor.data.ISurveyorData; -import com.bingce.controlapphelper.surveyor.method.AverageValueMethod; import com.bingce.controlapphelper.surveyor.method.RadianMethod; -import com.bingce.controlapphelper.surveyor.method.ValueOf2cMethod; -import com.bingce.controlapphelper.surveyor.method.model.CacheResult; import com.bingce.controlapphelper.surveyor.method.model.SdAngleValueType; -import com.bingce.controlapphelper.util.IdUtil; -import com.bingce.controlapphelper.util.SettingValueUtil; import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.App; import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.surveyor.method.AverageValueMethod; +import com.bingce.controlnetwork.surveyor.method.ValueOf2cMethod; +import com.bingce.controlnetwork.surveyor.method.model.CacheResult; +import com.bingce.controlnetwork.util.IdUtil; import com.bingce.utils.Util; -import org.jetbrains.annotations.NotNull; - -public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { - private final Context context; - private final TextView leftLabel; - private final TextView rightLabel; - - public final TextView pointName; - public final TextView heightValue; - public final TextView prismValue; - - public final TextView leftAngleHor1; - public final TextView leftAngleHor2; - public final TextView leftAngleVer1; - public final TextView leftAngleVer2; - public final TextView leftDistance1; - public final TextView leftDistance2; - - public final TextView rightAngleHor1; - public final TextView rightAngleHor2; - public final TextView rightAngleVer1; - public final TextView rightAngleVer2; - public final TextView rightDistance1; - public final TextView rightDistance2; - - public final TextView averageHorAngle; - public final TextView averageVerAngle; - public final TextView averageDistance; - - public final View selectMask; - - public final TextView _2c; - public final TextView _i; - public final TextView _2d; - - public final TextView distanceTitle; - private final View itemView; - - public SurveyorDataViewHolder(Context context, @NonNull @NotNull View itemView) { - super(itemView); - this.context = context; - leftLabel = itemView.findViewById(R.id.left_label); - rightLabel = itemView.findViewById(R.id.right_label); - - pointName = itemView.findViewById(R.id.pointName); - heightValue = itemView.findViewById(R.id.height_value); - prismValue = itemView.findViewById(R.id.prism_value); - - leftAngleHor1 = itemView.findViewById(R.id.left_angle_hor_1); - leftAngleHor2 = itemView.findViewById(R.id.left_angle_hor_2); - leftAngleVer1 = itemView.findViewById(R.id.left_angle_ver_1); - leftAngleVer2 = itemView.findViewById(R.id.left_angle_ver_2); - leftDistance1 = itemView.findViewById(R.id.left_distance_1); - leftDistance2 = itemView.findViewById(R.id.left_distance_2); - - rightAngleHor1 = itemView.findViewById(R.id.right_angle_hor_1); - rightAngleHor2 = itemView.findViewById(R.id.right_angle_hor_2); - rightAngleVer1 = itemView.findViewById(R.id.right_angle_ver_1); - rightAngleVer2 = itemView.findViewById(R.id.right_angle_ver_2); - rightDistance1 = itemView.findViewById(R.id.right_distance_1); - rightDistance2 = itemView.findViewById(R.id.right_distance_2); - - averageHorAngle = itemView.findViewById(R.id.average_angle_hor); - averageVerAngle = itemView.findViewById(R.id.average_angle_ver); - averageDistance = itemView.findViewById(R.id.average_distance); - - selectMask = itemView.findViewById(R.id.mask); - - _2c = itemView.findViewById(R.id.value_2c); - _i = itemView.findViewById(R.id.value_i); - _2d = itemView.findViewById(R.id.value_2d); - - distanceTitle = itemView.findViewById(R.id.distance_title); - this.itemView = itemView; +import blankj.utilcode.util.Utils; + + +public class SurveyorDataViewHolder extends AbstractSurveyorDataViewHolder { + + public SurveyorDataViewHolder(Context context, @NonNull View itemView) { + super(context, itemView); } + @Override public void setup(int itemIndex, String stationId, boolean showSlopDistance, @@ -117,11 +50,12 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { //当前非跳过点背景黄边白色 selectMask.setBackground(Tools.getDrawable(R.drawable.select_mask)); } else { - if (cachedData.isPointAbandon(currentCycleIndex, itemIndex)) { - selectMask.setBackground(Tools.getDrawable(R.drawable.bg_gray_3)); - } else { - selectMask.setBackgroundColor(Tools.getColor(R.color.white)); - } +// if (cachedData.isAbandonPoint(currentCycleIndex, itemIndex)) { +// selectMask.setBackground(Tools.getDrawable(R.drawable.bg_skip)); +// } else { +// selectMask.setBackgroundColor(Tools.getColor(R.color.white)); +// } + selectMask.setBackgroundColor(Tools.getColor(R.color.white)); } //初始化 @@ -144,17 +78,21 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { _i.setText(ORIGINAL_VALUE); _2d.setText(ORIGINAL_VALUE); - boolean aloneDistance = cachedData.isAloneDistance(currentCycleIndex, itemIndex); + + boolean excludeDistance = isExcluceDistance(cachedData, currentCycleIndex, itemIndex); + boolean excludeVer = isExcluceVer(cachedData, currentCycleIndex, itemIndex); //如果当前正在测量,使用缓存数据设置相应信息 LeftOrRight surveyorState = surveyorData.leftOrRight(); if (currentSurveyorIndex == itemIndex) { if (surveyorState == LeftOrRight.left) { if (surveyorData.hasSurveyor1()) { - setValue(aloneDistance, TYPE_LEFT1, surveyorData.getAngleHor1(), surveyorData.getAngleVer1(), surveyorData.getDistance1()); + setValue(TYPE_LEFT1, surveyorData.getAngleHor1(), + surveyorData.getAngleVer1(), surveyorData.getDistance1(), excludeVer, excludeDistance); } if (surveyorData.hasSurveyor2()) { - setValue(aloneDistance, TYPE_LEFT2, surveyorData.getAngleHor2(), surveyorData.getAngleVer2(), surveyorData.getDistance2()); + setValue(TYPE_LEFT2, surveyorData.getAngleHor2(), surveyorData.getAngleVer2(), + surveyorData.getDistance2(), excludeVer, excludeDistance); } //设置颜色 setTextColor(TYPE_LEFT1, R.color.value_1_selected); @@ -162,10 +100,12 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { leftLabel.setTextColor(context.getResources().getColor(R.color.value_1_selected)); } else if (surveyorState == LeftOrRight.right) { if (surveyorData.hasSurveyor1()) { - setValue(aloneDistance, TYPE_RIGHT1, surveyorData.getAngleHor1(), surveyorData.getAngleVer1(), surveyorData.getDistance1()); + setValue(TYPE_RIGHT1, surveyorData.getAngleHor1(), surveyorData.getAngleVer1(), + surveyorData.getDistance1(), excludeVer, excludeDistance); } if (surveyorData.hasSurveyor2()) { - setValue(aloneDistance, TYPE_RIGHT2, surveyorData.getAngleHor2(), surveyorData.getAngleVer2(), surveyorData.getDistance2()); + setValue(TYPE_RIGHT2, surveyorData.getAngleHor2(), surveyorData.getAngleVer2(), + surveyorData.getDistance2(), excludeVer, excludeDistance); } //设置颜色 setTextColor(TYPE_RIGHT1, R.color.value_1_selected); @@ -203,14 +143,14 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { } String pointId = cachedData.pointId(currentCycleIndex, itemIndex); - String leftRecordId = IdUtil.createSurveyorRecordId(stationId, currentCycleIndex, pointId, LeftOrRight.left); + String leftRecordId = IdUtil.surveyorRecordKey(stationId, currentCycleIndex, pointId, LeftOrRight.left); if (!skipLeft1) { DataCategory dataCategory = cachedData.valueState(leftRecordId, 0); if (!dataCategory.isEmptyData()) { - setValue(aloneDistance, TYPE_LEFT1, + setValue(TYPE_LEFT1, cachedData.angleHor1(leftRecordId), cachedData.angleVer1(leftRecordId), - cachedData.distance1(leftRecordId)); + cachedData.distance1(leftRecordId), excludeVer, excludeDistance); } if (dataCategory.isNeedResurvey()) { setTextColor(TYPE_LEFT1, R.color.value_dirty); @@ -221,10 +161,10 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { if (!skipLeft2) { DataCategory dataCategory = cachedData.valueState(leftRecordId, 1); if (!dataCategory.isEmptyData()) { - setValue(aloneDistance, TYPE_LEFT2, + setValue(TYPE_LEFT2, cachedData.angleHor2(leftRecordId), cachedData.angleVer2(leftRecordId), - cachedData.distance2(leftRecordId)); + cachedData.distance2(leftRecordId), excludeVer, excludeDistance); } if (dataCategory.isNeedResurvey()) { setTextColor(TYPE_LEFT2, R.color.value_dirty); @@ -232,14 +172,14 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { setTextColor(TYPE_LEFT2, R.color.value_resurveyed); } } - String rightRecordId = IdUtil.createSurveyorRecordId(stationId, currentCycleIndex, pointId, LeftOrRight.right); + String rightRecordId = IdUtil.surveyorRecordKey(stationId, currentCycleIndex, pointId, LeftOrRight.right); if (!skipRight1) { DataCategory dataCategory = cachedData.valueState(rightRecordId, 0); if (!dataCategory.isEmptyData()) { - setValue(aloneDistance, TYPE_RIGHT1, + setValue(TYPE_RIGHT1, cachedData.angleHor1(rightRecordId), cachedData.angleVer1(rightRecordId), - cachedData.distance1(rightRecordId)); + cachedData.distance1(rightRecordId), excludeVer, excludeDistance); } if (dataCategory.isNeedResurvey()) { setTextColor(TYPE_RIGHT1, R.color.value_dirty); @@ -250,10 +190,10 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { if (!skipRight2) { DataCategory dataCategory = cachedData.valueState(rightRecordId, 1); if (!dataCategory.isEmptyData()) { - setValue(aloneDistance, TYPE_RIGHT2, + setValue(TYPE_RIGHT2, cachedData.angleHor2(rightRecordId), cachedData.angleVer2(rightRecordId), - cachedData.distance2(rightRecordId)); + cachedData.distance2(rightRecordId), excludeVer, excludeDistance); } if (dataCategory.isNeedResurvey()) { setTextColor(TYPE_RIGHT2, R.color.value_dirty); @@ -262,39 +202,43 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { } } - //均值(中值) int surveyorCount = surveyorData.surveyorCount(); CacheResult horAngleLeftAndRightAverageValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.horAngle, leftRecordId, rightRecordId, surveyorCount, cachedData); - + //水平角中值 if (horAngleLeftAndRightAverageValue.validate) { double radian = RadianMethod.formatRadian(horAngleLeftAndRightAverageValue.value); averageHorAngle.setText(RadianMethod.dmsStringOf(radian)); } else { averageHorAngle.setText(ORIGINAL_VALUE); } - - CacheResult verAngleLeftAndRightAverageValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.verAngle, leftRecordId, rightRecordId, surveyorCount, cachedData); - if (verAngleLeftAndRightAverageValue.validate) {//显示天顶距 - averageVerAngle.setText(RadianMethod.dmsStringOf(Math.PI / 2 - verAngleLeftAndRightAverageValue.value)); - } else { + + //垂直角中值 + if (excludeVer) { averageVerAngle.setText(ORIGINAL_VALUE); + } else { + if (verAngleLeftAndRightAverageValue.validate) { + //显示天顶距 + averageVerAngle.setText(RadianMethod.dmsStringOf(Math.PI / 2 - verAngleLeftAndRightAverageValue.value)); + } else { + averageVerAngle.setText(ORIGINAL_VALUE); + } } + //距离中值 CacheResult distanceLeftAndRightAverageValue = AverageValueMethod.leftAndRightValue(SdAngleValueType.distance, leftRecordId, rightRecordId, surveyorCount, cachedData); - if (aloneDistance) { + if (excludeDistance) { averageDistance.setText(ORIGINAL_VALUE); } else { if (distanceLeftAndRightAverageValue.validate) { - averageDistance.setText(Util.formatDouble2String(distanceLeftAndRightAverageValue.value, - SettingValueUtil.getLengthDecimalPoint())); + averageDistance.setText(Util.formatDouble2String(distanceLeftAndRightAverageValue.value, ((App) Utils.getApp()).notNumber)); } else { averageDistance.setText(ORIGINAL_VALUE); } @@ -302,23 +246,28 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { //设置2c、i、2d CacheResult value2C = ValueOf2cMethod.valueOf2C(SdAngleValueType.horAngle, - itemIndex, stationId, surveyorData, currentCycleIndex, cachedData); + stationId, currentCycleIndex, itemIndex, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); if (value2C.validate && horAngleLeftAndRightAverageValue.validate) { _2c.setText(String.format("%s″", Util.formatDouble2String(value2C.value, 1))); } else { _2c.setText(ORIGINAL_VALUE); } - CacheResult valueI = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, - itemIndex, stationId, surveyorData, currentCycleIndex, cachedData); - if (valueI.validate && verAngleLeftAndRightAverageValue.validate) { - _i.setText(String.format("%s″", Util.formatDouble2String(valueI.value, 1))); - } else { + + if (excludeVer) { _i.setText(ORIGINAL_VALUE); + } else { + CacheResult valueI = ValueOf2cMethod.valueOf2C(SdAngleValueType.verAngle, + stationId, currentCycleIndex, itemIndex, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); + if (valueI.validate && verAngleLeftAndRightAverageValue.validate) { + _i.setText(String.format("%s″", Util.formatDouble2String(valueI.value, 1))); + } else { + _i.setText(ORIGINAL_VALUE); + } } CacheResult value2D = ValueOf2cMethod.valueOf2C(SdAngleValueType.distance, - itemIndex, stationId, surveyorData, currentCycleIndex, cachedData); - if (aloneDistance) { + stationId, currentCycleIndex, itemIndex, surveyorData, cycleRecorder.currentCycleIndex(), cachedData); + if (excludeDistance) { _2d.setText(ORIGINAL_VALUE); } else { if (value2D.validate && distanceLeftAndRightAverageValue.validate) { @@ -330,24 +279,48 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { } + /** + * 是否排除距离 + */ + private boolean isExcluceDistance(ICachedData cachedData, int currentCycleIndex, int itemIndex) { + return cachedData.isWellSteelPoint(currentCycleIndex, itemIndex) + || cachedData.isAloneMeasureDistancePoint(currentCycleIndex, itemIndex) + || cachedData.getSurveyorPoint(currentCycleIndex, itemIndex).isMeasureDistanceNot(); + } + + /** + * 是否排除垂直角 + */ + private boolean isExcluceVer(ICachedData cachedData, int currentCycleIndex, int itemIndex) { + return cachedData.getSurveyorPoint(currentCycleIndex, itemIndex).isMeasureVerNot(); + } + private void setTextColor(int type, int value) { angleHor(type).setTextColor(context.getResources().getColor(value)); angleVer(type).setTextColor(context.getResources().getColor(value)); distance(type).setTextColor(context.getResources().getColor(value)); } - private void setValue(boolean aloneDistance, int type, double angleHor, double angleVer, double distance) { + private void setValue(int type, double angleHor, double angleVer, double distance, + boolean excludeVer, boolean excludeDistance) { //判断是否测水平角 - String angleVerS = RadianMethod.dmsStringOf(angleVer); - String distanceS = ORIGINAL_VALUE; - if (!aloneDistance) { - distanceS = Util.formatDouble2String(distance, - SettingValueUtil.getLengthDecimalPoint()); + String distanceString; + if (excludeDistance) { + distanceString = ORIGINAL_VALUE; + } else { + distanceString = Util.formatDouble2String(distance, ((App) Utils.getApp()).notNumber); + } + //判断是否测水平角 + String verString; + if (excludeVer) { + verString = ORIGINAL_VALUE; + } else { + verString = RadianMethod.dmsStringOf(angleVer); } setValue(type, RadianMethod.dmsStringOf(angleHor), - angleVerS, - distanceS); + verString, + distanceString); } private void setValue(int type, String angleHor, String angleVer, String distance) { @@ -399,10 +372,4 @@ public class SurveyorDataViewHolder extends RecyclerView.ViewHolder { return rightDistance2; } - private static final int TYPE_LEFT1 = 1; - private static final int TYPE_LEFT2 = 2; - private static final int TYPE_RIGHT1 = 3; - private static final int TYPE_RIGHT2 = 4; - private static final String ORIGINAL_VALUE = "-"; - private static final String SKIP_VALUE = "*"; } diff --git a/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataWellDistanceViewHolder.java b/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataWellDistanceViewHolder.java new file mode 100644 index 0000000..8aa649e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/ui/vh/SurveyorDataWellDistanceViewHolder.java @@ -0,0 +1,254 @@ +package com.bingce.controlnetwork.ui.vh; + +import android.content.Context; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bingce.controlapphelper.datasource.database.alonedistance.AloneDistanceRecord; +import com.bingce.controlapphelper.datasource.database.alonedistance.WellDistance; +import com.bingce.controlapphelper.model.LeftOrRight; +import com.bingce.controlapphelper.util.Tools; +import com.bingce.controlnetwork.R; +import com.bingce.controlnetwork.surveyor.data.ICachedData; +import com.bingce.controlnetwork.surveyor.data.ICycleRecorder; +import com.bingce.controlnetwork.surveyor.data.ISurveyorData; +import com.bingce.controlnetwork.util.IdUtil; +import com.bingce.utils.Util; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + + +public class SurveyorDataWellDistanceViewHolder extends RecyclerView.ViewHolder { + private final Context context; + private final TextView leftLabel;//平距或斜距 + + private final TextView pointName; +// private final TextView tvWeatherAmend; + private final TextView heightValue; + private final TextView prismValue; + + private final List distanceViews; + private final TextView tvFirstRound1, tvFirstRound2, tvFirstRound3, tvFirstRound4; + private final TextView tvSecondRound1, tvSecondRound2, tvSecondRound3, tvSecondRound4; + + private final TextView tvFirstRoundAverageDistance, tvSecondRoundAverageDistance;//第一,第二测回中值 + private final TextView tvFirstRound2D, tvSecondRound2D;//第一,第二测回2D + + private final View selectMask;//黄框 + + private final int ROUND_NUM = 2; + private final int EVERY_ROUND_NUM = 4; + + private final int notNumberForDistance = 4; + + private List realDistanceValues = new ArrayList<>(); + + public SurveyorDataWellDistanceViewHolder(Context context, @NonNull @NotNull View itemView) { + super(itemView); + this.context = context; + + pointName = itemView.findViewById(R.id.pointName); +// tvWeatherAmend = itemView.findViewById(R.id.tvWeatherAmend); + heightValue = itemView.findViewById(R.id.height_value); + prismValue = itemView.findViewById(R.id.prism_value); + + leftLabel = itemView.findViewById(R.id.left_label); + + tvFirstRound1 = itemView.findViewById(R.id.tvFirstRound1); + tvFirstRound2 = itemView.findViewById(R.id.tvFirstRound2); + tvFirstRound3 = itemView.findViewById(R.id.tvFirstRound3); + tvFirstRound4 = itemView.findViewById(R.id.tvFirstRound4); + tvSecondRound1 = itemView.findViewById(R.id.tvSecondRound1); + tvSecondRound2 = itemView.findViewById(R.id.tvSecondRound2); + tvSecondRound3 = itemView.findViewById(R.id.tvSecondRound3); + tvSecondRound4 = itemView.findViewById(R.id.tvSecondRound4); + + distanceViews = new ArrayList<>(); + distanceViews.add(tvFirstRound1); + distanceViews.add(tvFirstRound2); + distanceViews.add(tvFirstRound3); + distanceViews.add(tvFirstRound4); + distanceViews.add(tvSecondRound1); + distanceViews.add(tvSecondRound2); + distanceViews.add(tvSecondRound3); + distanceViews.add(tvSecondRound4); + + + tvFirstRoundAverageDistance = itemView.findViewById(R.id.tvFirstRoundAverageDistance); + tvSecondRoundAverageDistance = itemView.findViewById(R.id.tvSecondRoundAverageDistance); + tvFirstRound2D = itemView.findViewById(R.id.tvFirstRound2D); + tvSecondRound2D = itemView.findViewById(R.id.tvSecondRound2D); + + selectMask = itemView.findViewById(R.id.mask); + } + + public void setup(int itemIndex, + String projectType, + String stationId, + boolean showSlopDistance, + ICachedData cachedData, + ICycleRecorder cycleRecorder, + ISurveyorData surveyorData) { + if (showSlopDistance) { + leftLabel.setText(R.string.distance_slope); + } else { + leftLabel.setText(R.string.distance_horizontal); + } + + int currentCycleIndex = 0; + int currentSurveyorIndex = surveyorData.currentIndex(); + + //设置当前测量状态标识 + if (currentSurveyorIndex == itemIndex) { + selectMask.setVisibility(View.VISIBLE); + } else { + selectMask.setVisibility(View.GONE); + } + + //初始化 + initDefault(); + + //设置值 + pointName.setText(cachedData.pointName(currentCycleIndex, itemIndex)); + heightValue.setText(cachedData.getPrismHeight(currentCycleIndex, itemIndex)); + prismValue.setText(cachedData.getPrismTypeName(currentCycleIndex, itemIndex)); + + //先清空下realDistanceValues保证数据不错乱,注意位置在前面 + clearRealDistanceValues(); + List distanceDatas = getDistanceDataFromCacheData(cachedData, stationId, currentCycleIndex, itemIndex); + setDistanceViewData(distanceDatas, showSlopDistance, currentSurveyorIndex == itemIndex); + + //设置中值和2d + if (!realDistanceValues.isEmpty()) { + int distanceSize = realDistanceValues.size(); + int hanNum = distanceSize / EVERY_ROUND_NUM; + if (hanNum >= 1) { + //有可以显示的中值 + if (hanNum == ROUND_NUM) { + //当满足两测回都可以显示中值和2d的时候 + setFirstRound2DAndAverageDistance(showSlopDistance); + setSecondRound2DAndAverageDistance(showSlopDistance); + } else { + //当满足第一测回可以显示中值和2d的时候 + setFirstRound2DAndAverageDistance(showSlopDistance); + } + } + } + + } + + /** + * 从缓存数据中读取距离数据 + * + * @param cachedData + * @param stationId + * @param currentCycleIndex + * @param itemIndex + * @return + */ + private List getDistanceDataFromCacheData(ICachedData cachedData, String stationId, int currentCycleIndex, int itemIndex) { + List distanceValues = null; + String pointId = cachedData.pointId(currentCycleIndex, itemIndex); + String recordId = IdUtil.surveyorRecordKey(stationId, currentCycleIndex, pointId, LeftOrRight.left); + AloneDistanceRecord wellRecord = cachedData.getWellRecord(recordId); + if (wellRecord != null) { + distanceValues = wellRecord.distanceValues; + } + return distanceValues; + } + + private void setFirstRound2DAndAverageDistance(boolean isSlop) { + List wellDistances = realDistanceValues.subList(0, EVERY_ROUND_NUM); + Double averageFirstRound = Tools.calculateCollectionDoubleAverage(wellDistances, isSlop); + Double maxSubMinFirstRound = Tools.calculateCollectionMaxSubMin(wellDistances, isSlop); + setAverageDistanceText(tvFirstRoundAverageDistance, averageFirstRound); + set2DText(tvFirstRound2D, maxSubMinFirstRound); + } + + private void setSecondRound2DAndAverageDistance(boolean isSlop) { + List wellDistances = realDistanceValues.subList(EVERY_ROUND_NUM, realDistanceValues.size()); + Double averageSecondRound = Tools.calculateCollectionDoubleAverage(wellDistances, isSlop); + Double maxSubMinSecondRound = Tools.calculateCollectionMaxSubMin(wellDistances, isSlop); + setAverageDistanceText(tvSecondRoundAverageDistance, averageSecondRound); + set2DText(tvSecondRound2D, maxSubMinSecondRound); + } + + + private void setTextColor(TextView tv, int value) { + tv.setTextColor(context.getResources().getColor(value)); + } + + private void setDistance(TextView tv, double distance) { + String distanceS; + if (distance == 0) { + distanceS = ORIGINAL_VALUE; + } else { + distanceS = Util.formatDouble2String(distance, notNumberForDistance); + } + tv.setText(distanceS); + } + + private void set2DText(TextView tv, double value) { + tv.setText(String.format("%smm", Util.formatDouble2String(value * 1000, 1))); + } + + private void setAverageDistanceText(TextView tv, double value) { + tv.setText(Util.formatDouble2String(value, notNumberForDistance)); + } + + /** + * 初始化 + */ + private void initDefault() { + leftLabel.setTextColor(context.getResources().getColor(R.color.value_1_normal)); + + initDefaultDistanceViewsData(); + + tvFirstRoundAverageDistance.setText(ORIGINAL_VALUE); + tvSecondRoundAverageDistance.setText(ORIGINAL_VALUE); + + tvFirstRound2D.setText(ORIGINAL_VALUE); + tvSecondRound2D.setText(ORIGINAL_VALUE); + } + + private void initDefaultDistanceViewsData() { + for (TextView textView : distanceViews) { + setDistance(textView, 0); + setTextColor(textView, R.color.value_1_normal); + } + } + + /** + * 设置view的数据 + * + * @param wellDistanceValues + * @param isSlop + * @param isSelected + */ + private void setDistanceViewData(List wellDistanceValues, boolean isSlop, boolean isSelected) { + if (wellDistanceValues == null) return; + for (int i = 0; i < wellDistanceValues.size(); i++) { + WellDistance wellDistance = wellDistanceValues.get(i); + TextView textView = distanceViews.get(i); + setDistance(textView, isSlop ? wellDistance.slopDistance : wellDistance.hovDistance); + setTextColor(textView, isSelected ? R.color.value_1_selected : R.color.value_1_normal); + //存一下 + realDistanceValues.add(wellDistance); + } + } + + private void clearRealDistanceValues() { + realDistanceValues.clear(); + } + + + private static final String ORIGINAL_VALUE = "-"; + + +} diff --git a/app/src/main/java/com/bingce/controlnetwork/util/IdUtil.java b/app/src/main/java/com/bingce/controlnetwork/util/IdUtil.java new file mode 100644 index 0000000..3fd20c3 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/util/IdUtil.java @@ -0,0 +1,10 @@ +package com.bingce.controlnetwork.util; + + +import com.bingce.controlapphelper.model.LeftOrRight; + +public class IdUtil { + public static String surveyorRecordKey(String stationId, int cycleIndex, String pointId, LeftOrRight leftOrRight) { + return stationId + cycleIndex + pointId + leftOrRight.name(); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/util/StationUtilPla.java b/app/src/main/java/com/bingce/controlnetwork/util/StationUtilPla.java new file mode 100644 index 0000000..03f48dd --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/util/StationUtilPla.java @@ -0,0 +1,121 @@ +package com.bingce.controlnetwork.util; + +import androidx.annotation.MainThread; +import androidx.annotation.WorkerThread; + +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory; +import com.bingce.controlapphelper.datasource.database.schedule.ISurveyorScheduleDataSource; +import com.bingce.controlapphelper.datasource.database.schedule.SurveyorScheduleRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord; +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint; +import com.bingce.controlapphelper.datasource.database.tolerance.detail.ToleranceDetailRecord; +import com.bingce.controlnetwork.bean.SurveyorScheduleConstants; +import com.bingce.controlnetwork.surveyor.data.CachedDataPointType; +import com.bingce.utils.ThreadPoolUtil; + +import java.util.ArrayList; +import java.util.List; + +public class StationUtilPla { + + /** + * 获取站的测回数 + * + * @return + */ + public static int getCycleCount(int measureWhat, SurveyorStationRecord stationRecord, ToleranceDetailRecord toleranceDetailRecordTj) { +// int cycleCount; +// if (measureWhat == StateConstantsTj.VALUE_MEASURE_WHAT_ANGLE_VER) { +// cycleCount = toleranceDetailRecordTj.getCycleCountVerAngle(); +// } else { +// cycleCount = toleranceDetailRecordTj.getCycleCount(); +// List items = stationRecord.getItems(); +// if (items != null && items.size() == 3 && toleranceDetailRecordTj.getTwoTargetCycle() > 0) { +// //两目标距离测回数 +// return toleranceDetailRecordTj.getTwoTargetCycle(); +// } +// } +// return cycleCount; + return toleranceDetailRecordTj.getCycleCount(); + } + + /** + * 返回测站中所有测点相关信息,不包含闭合点 + * + * @param stationId 测站id + * @param cachedDataPointType + * @return StationItem列表 + */ + @WorkerThread + public static List itemListWithoutClosedItems(SurveyorStationRecord stationRecord, String stationId, CachedDataPointType cachedDataPointType) { + if (stationRecord == null) { + stationRecord = SurveyorDatabaseFactory + .instance + .getSurveyorStation() + .getRecordSync(stationId); + } + if (stationRecord == null) { + return null; + } + List stationItems = stationRecord.items; + if (stationItems == null || stationItems.isEmpty()) { + return null; + } + //过滤掉测站点和闭合点,只保留TYPE_POINT类型数据 + List items = new ArrayList<>(); + for (SurveyorPoint item : stationItems) { + if (item == null) { + continue; + } + + if (!SurveyorPoint.TYPE_POINT.equals(item.getType())) { + continue; + } + + if (cachedDataPointType == CachedDataPointType.ALL_POINT) { + + } else if (cachedDataPointType == CachedDataPointType.STEEL_POINT) { + if (!item.isWellSteel()) { + continue; + } + } else if (cachedDataPointType == CachedDataPointType.ALONE_MEASURE_DISTANCE_POINT) { + if (!item.isAloneMeasureDistance()) { + continue; + } + } else if (cachedDataPointType == CachedDataPointType.ALONE_MEASURE_VER_ANGLE_POINT) { + if (item.isMeasureVerNot()) { + continue; + } + } + + items.add(item); + } + return items; + } + + /** + * 检测测站是否可以平平差 + */ + @MainThread + public static void checkStationCanAdjust(String stationId, int measureWhat, ICanAdjust canAdjust) { + ThreadPoolUtil.execute(() -> { + String stationStatus = getStationStatus(stationId, measureWhat); + canAdjust.adjust(SurveyorScheduleConstants.STATUE_VALUE_CHECKED.equals(stationStatus)); + }); + } + + private static String getStationStatus(String stationId, int measureWhat) { + ISurveyorScheduleDataSource surveyorScheduleDataSource = SurveyorDatabaseFactory.instance.getScheduleDataSource(); + SurveyorScheduleRecord surveyorScheduleRecord = surveyorScheduleDataSource + .findScheduleSync(SurveyorScheduleConstants.stationAllCycleScheduleKey(stationId, measureWhat)); + String stationStatue = SurveyorScheduleConstants.STATUE_VALUE_NO_COMPLETED; + if (surveyorScheduleRecord != null) { + stationStatue = surveyorScheduleRecord.getStatue(); + } + return stationStatue; + } + + public interface ICanAdjust { + void adjust(boolean isCanAdjust); + } +} diff --git a/app/src/main/java/com/bingce/controlnetwork/util/SupportAutoSurveyorUtil.kt b/app/src/main/java/com/bingce/controlnetwork/util/SupportAutoSurveyorUtil.kt new file mode 100644 index 0000000..2c1ba92 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/util/SupportAutoSurveyorUtil.kt @@ -0,0 +1,26 @@ +package com.bingce.controlnetwork.util + +import blankj.utilcode.util.AppUtils +import blankj.utilcode.util.Utils +import com.bingce.controlapphelper.surveyor.test.Test +import com.bingce.controlnetwork.App +import com.bingce.totalstation.TotalStation + +object SupportAutoSurveyorUtil { + @JvmStatic + fun isSupportAuto(): Boolean { + var supportAuto = false + if (Test.DEBUG) { + supportAuto = true + } + + val isSupportAutoMode = TotalStation.getInstance().isSupportMotor + if (isSupportAutoMode && + (AppUtils.isAppDebug() || CheckRegUtil.checkReg((Utils.getApp() as App).registerCodeV2)) + ) { + supportAuto = true + } + return supportAuto + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_project_surveyor_station_detail_layout_well.xml b/app/src/main/res/layout/fragment_project_surveyor_station_detail_layout_well.xml new file mode 100644 index 0000000..0e0f72d --- /dev/null +++ b/app/src/main/res/layout/fragment_project_surveyor_station_detail_layout_well.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + +