diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 013c669..b0ea484 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -198,7 +198,10 @@ android:name=".ui.instrument.coordinatesystem.BingCeCoordinateSystemActivity" android:exported="true" android:windowSoftInputMode="adjustResize|stateHidden" /> - + \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/BingCeCoordinateSystemActivity.java b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/BingCeCoordinateSystemActivity.java index b2c43a7..dcb6369 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/BingCeCoordinateSystemActivity.java +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/BingCeCoordinateSystemActivity.java @@ -60,18 +60,21 @@ public class BingCeCoordinateSystemActivity extends AutoLandscapeBingCeActivity Fragment finalCoordinatorFragment = coordinatorFragment; binding.activityCoordinateSystemBtnQuit.setOnClickListener(v -> { + //退出 if (finalCoordinatorFragment instanceof CoordinateSystemContainerFragment) { ((CoordinateSystemContainerFragment) finalCoordinatorFragment).onQuitClicked(); } }); binding.activityCoordinateSystemBtnAccept.setOnClickListener(v -> { + //接受 if (finalCoordinatorFragment instanceof CoordinateSystemContainerFragment) { ((CoordinateSystemContainerFragment) finalCoordinatorFragment).onAcceptClicked(); } }); binding.activityCoordinateSystemBtnCalc.setOnClickListener(v -> { + //参数解算 if (finalCoordinatorFragment instanceof CoordinateSystemContainerFragment) { ((CoordinateSystemContainerFragment) finalCoordinatorFragment).onCalcClicked(); } @@ -83,7 +86,7 @@ public class BingCeCoordinateSystemActivity extends AutoLandscapeBingCeActivity @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_activity_rtk_coordinate_system, menu); +// getMenuInflater().inflate(R.menu.menu_activity_rtk_coordinate_system, menu); return super.onCreateOptionsMenu(menu); } diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java index c3ba102..af2bd6c 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java @@ -25,14 +25,8 @@ import com.bingce.coordlib.util.CoordinateSystemUtil; import com.bingce.data.cache.AbstractCachedObserver; import com.bingce.data.database.CoordinateSystemDb; import com.bingce.data.database.DBQueryConstant; -import com.bingce.data.database.KeyValueDb; -import com.bingce.data.database.ProjectDb; import com.bingce.data.surveyor.designdata.coordinate.CoordinateSystemConstants; import com.bingce.data.surveyor.designdata.coordinate.CoordinateSystemRecord; -import com.bingce.data.surveyor.designdata.kv.KeyValueConstants; -import com.bingce.data.surveyor.designdata.kv.KeyValueRecord; -import com.bingce.data.surveyor.designdata.project.ProjectConstants; -import com.bingce.data.surveyor.designdata.project.ProjectRecord; import com.bingce.device.Device; import com.bingce.device.ui.coordinatesystem.event.UpdateCoordinateSystemEvent; import com.bingce.device.ui.coordinatesystem.fragment.AbstractCoordinateSystemContainerFragment; @@ -45,7 +39,6 @@ import com.bingce.device.ui.coordinatesystem.fragment.GridTransformFragment; import com.bingce.device.ui.coordinatesystem.fragment.ProjectionFragment; import com.bingce.device.ui.utils.CoordSysShareUtil; import com.bingce.dialog.DialogUtils; -import com.bingce.error.BingCeErrorCode; import com.bingce.event.SingleMessageEvent; import com.bingce.surveyorBase.R; import com.bingce.ui.coordinatesystem.PresetCoordinateSystemV2Activity; @@ -54,6 +47,7 @@ import com.bingce.utils.ThreadPoolUtil; import com.bingce.utils.ValidateUtil; import com.flyco.tablayout.SlidingTabLayout; import com.project.survey.ui.instrument.coordinatesystem.CachedCurrentCoordinateSystem; +import com.project.survey.ui.instrument.mobilestationmode.base.RtkPointCorrectActivity; import com.rengwuxian.materialedittext.MaterialEditText; import org.greenrobot.eventbus.EventBus; @@ -170,14 +164,17 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC public void onCalcClicked() { mSlidingTabLayout.setCurrentTab(1, true); - new MaterialDialog.Builder(getActivity()) + new MaterialDialog.Builder(requireContext()) .title(R.string.hint) .content(R.string.seven_or_four_para_hint) .positiveText(R.string.go_to_config) .negativeText(R.string.configured) .onNegative((dialog, which) -> { save(() -> { - EventBus.getDefault().post(new SingleMessageEvent("coordinate_system_parameter_calc")); + Intent intent = new Intent(requireContext(), RtkPointCorrectActivity.class); + intent.putExtra("from", 1); + startActivity(intent); +// EventBus.getDefault().post(new SingleMessageEvent("coordinate_system_parameter_calc")); }); }) .show(); @@ -200,20 +197,21 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC } else { ThreadPoolUtil.execute(() -> { //搜索当前坐标系 - KeyValueRecord currentProjectConfig = KeyValueDb.getInstance().findData(KeyValueConstants.KEY_CURRENT_PROJECT_ID); - if (currentProjectConfig == null) { - BingCeErrorCode.toast(BingCeErrorCode.NO_CURRENT_PROJECT); - return; - } - ProjectRecord currentProjectRecord = ProjectDb.getInstance() - .rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectConfig.value)); - if (currentProjectRecord == null) { - BingCeErrorCode.toast(BingCeErrorCode.NO_FOUND_PROJECT_BY_ID); - return; - } - currentProjectRecord.coordinateSystem = coordinateSystem; - ProjectDb.getInstance().save(currentProjectRecord); - +// KeyValueRecord currentProjectConfig = KeyValueDb.getInstance().findData(KeyValueConstants.KEY_CURRENT_PROJECT_ID); +// if (currentProjectConfig == null) { +// BingCeErrorCode.toast(BingCeErrorCode.NO_CURRENT_PROJECT); +// return; +// } +// ProjectRecord currentProjectRecord = ProjectDb.getInstance() +// .rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectConfig.value)); +// if (currentProjectRecord == null) { +// BingCeErrorCode.toast(BingCeErrorCode.NO_FOUND_PROJECT_BY_ID); +// return; +// } +// currentProjectRecord.coordinateSystem = coordinateSystem; +// ProjectDb.getInstance().save(currentProjectRecord); + + // TODO: 2024/8/15 存坐标系 //切换线路 ThreadPoolUtil.executeInMain(success); }); diff --git a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/AbstractRtkMatchingPointsActivity.java b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/AbstractRtkMatchingPointsActivity.java new file mode 100644 index 0000000..1c1d249 --- /dev/null +++ b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/AbstractRtkMatchingPointsActivity.java @@ -0,0 +1,383 @@ +package com.project.survey.ui.instrument.mobilestationmode.base; + +import android.graphics.Color; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; + +import androidx.annotation.WorkerThread; + +import com.bingce.coordlib.model.Blh; +import com.bingce.coordlib.model.BlhCoordinatePair; +import com.bingce.coordlib.model.Coordinate; +import com.bingce.coordlib.model.CoordinateSystem; +import com.bingce.device.Device; +import com.bingce.device.ui.AbstractSurveyActivity; +import com.bingce.utils.ColorUtil; +import com.bingce.utils.IOnSingleGetCallback; +import com.bingce.utils.SoftKeyUtils; +import com.bingce.utils.ThreadPoolUtil; +import com.bingce.utils.Util; +import com.daimajia.numberprogressbar.NumberProgressBar; +import com.rengwuxian.materialedittext.MaterialEditText; + +import blankj.utilcode.util.ToastUtils; +import device.ui.Rid; +import device.ui.Rlayout; +import device.ui.Rstring; + +public abstract class AbstractRtkMatchingPointsActivity extends AbstractSurveyActivity { + private EditText et_0; + private MaterialEditText met_b, met_l, met_h, met_name, met_x, met_y, met_z; + private Button mBtnCollect, mBtnSave; + private CheckBox mCheckUseH, mCheckUseV; + private CoordinateSystem coordinateSystem; + private int mTimes = -1, position = -1; + private double mSumB, mSumL, mSumH; + private View mBtnOpen1, mBtnOpen2; + private double b, l, h, x, y, z; + private NumberProgressBar progressBar; +// protected final CachedCurrentCoordinateSystem cachedCoordinateSystem = new CachedCurrentCoordinateSystem(this); + + @Override + protected int getLayoutId() { + return Rlayout.activity_rtk_matching_points(); + } + + @Override + protected void initView() { + position = getIntent().getIntExtra("position", -1); + et_0 = findViewById(Rid.activity_rtk_matching_points_et_0()); + met_b = findViewById(Rid.activity_rtk_matching_points_met_b()); + met_l = findViewById(Rid.activity_rtk_matching_points_met_l()); + met_h = findViewById(Rid.activity_rtk_matching_points_met_h()); + met_name = findViewById(Rid.activity_rtk_matching_points_met_name()); + met_x = findViewById(Rid.activity_rtk_matching_points_met_x()); + met_y = findViewById(Rid.activity_rtk_matching_points_met_y()); + met_z = findViewById(Rid.activity_rtk_matching_points_met_z()); + mBtnOpen1 = findViewById(Rid.activity_rtk_matching_points_btn_open1()); + mBtnOpen2 = findViewById(Rid.activity_rtk_matching_points_btn_open2()); + mBtnCollect = findViewById(Rid.activity_rtk_matching_points_btn_collect()); + mBtnSave = findViewById(Rid.activity_rtk_matching_points_btn_save()); + mCheckUseH = findViewById(Rid.activity_rtk_matching_points_cb_use_horizontal()); + mCheckUseV = findViewById(Rid.activity_rtk_matching_points_cb_use_vertical()); + progressBar = findViewById(Rid.activity_rtk_matching_points_progressbar()); + progressBar.setReachedBarColor(ColorUtil.getColorPrimary(this)); + + mBtnCollect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// et_0.requestFocus();//作用:输入框不聚焦,防止实测坐标后页面自动滑动到顶部,同样避免RTK继续后输入框没有失效焦点,导致再输入内容输入法自动隐藏的问题 +// CommonUtils.hideSoftInput(); + SoftKeyUtils.hideSoftKey(); + + Device.getInstance().isRtkRunning = true; + mTimes = 0; + mSumB = 0; + mSumL = 0; + mSumH = 0; + met_b.setText(""); + met_l.setText(""); + met_h.setText(""); + progressBar.setProgress(0); + } + }); + mBtnSave.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// et_0.requestFocus();//作用:输入框不聚焦,防止实测坐标后页面自动滑动到顶部 +// CommonUtils.hideSoftInput(); + SoftKeyUtils.hideSoftKey(); + if (checkActionEnable()) { + x = Double.parseDouble(met_x.getText().toString()); + y = Double.parseDouble(met_y.getText().toString()); + z = Double.parseDouble(met_z.getText().toString()); + b = Math.toDegrees(Util.dmsStringToRadian(met_b.getText().toString(), false)); + l = Math.toDegrees(Util.dmsStringToRadian(met_l.getText().toString(), false)); + h = Double.parseDouble(met_h.getText().toString()); + + if (position >= 0 && position < coordinateSystem.getPairs().size()) { + coordinateSystem.getPairs().set(position, new BlhCoordinatePair(met_name.getText().toString(), new Blh(b, l, h), new Coordinate(x, y, z), mCheckUseH.isChecked(), mCheckUseV.isChecked())); + } else { + coordinateSystem.getPairs().add(new BlhCoordinatePair(met_name.getText().toString(), new Blh(b, l, h), new Coordinate(x, y, z), mCheckUseH.isChecked(), mCheckUseV.isChecked())); + } + ThreadPoolUtil.execute(() -> { +// ProjectDb.getInstance().updateCurrentCoordinator(coordinateSystem); + save(coordinateSystem); + runOnUiThread(() -> { + setResult(RESULT_OK); + finish(); + }); + }); + } + } + }); + mBtnOpen1.setOnClickListener(view -> { + et_0.requestFocus(); + SoftKeyUtils.hideSoftKey(); + selectBLH(); +// CommonUtils.hideSoftInput(); +// new MaterialDialog.Builder(RtkMatchingPointsActivity.this) +// .title(Rstring.data_source) +// .items(new String[]{getString(Rstring.point_survey_point_library)}) +// .itemsCallback((dialog, itemView, which, text) -> { +// switch (which) { +// case 0: +// CoordinatePointsLibraryActivity.pickPoint(this, (name, code, x, y, z, b, l, h) -> { +// onPicked(b, l, h); +// }); +// break; +// } +// }).show(); + }); + mBtnOpen2.setOnClickListener(view -> { + et_0.requestFocus(); + SoftKeyUtils.hideSoftKey(); + selectXYZ(); +// CommonUtils.hideSoftInput(); +// new MaterialDialog.Builder(RtkMatchingPointsActivity.this) +// .title(Rstring.data_source) +// .items(new String[]{getString(Rstring.road_control_point), getString(Rstring.global_control_point), getString(Rstring.point_survey_point_library), getString(Rstring.staking_point_library)}) +// .itemsCallback((dialog, itemView, which, text) -> { +// switch (which) { +// case 0: +// ControlPointsNewActivity.pickPoint(this, false, (name, code, x, y, z, remarks) -> { +// onPicked(name, x, y, z); +// }); +// break; +// case 1: +// ControlPointsNewActivity.pickPoint(this, true, (name, code, x, y, z, remarks) -> { +// onPicked(name, x, y, z); +// }); +// break; +// case 2: +// CoordinatePointsLibraryActivity.pickPoint(this, (name, code, x, y, z, b, l, h) -> { +// onPicked(name, x, y, z); +// }); +// break; +// case 3: +// StakingJobActivity.pickPoint(this, (name, x, y, z) -> { +// onPicked(name, x, y, z); +// }); +// break; +// } +// }).show(); + }); + initMaterialEditTextColor(); + +// cachedCoordinateSystem.observe(new AbstractCachedObserver() { +// @Override +// public void onChanged(boolean isFirstTimeDataChanged, CoordinateSystem coordinateSystem) { +// if (isFirstTimeDataChanged) { +// init(coordinateSystem); +// } +// } +// }); + loadCurrentCoordinateSystem(this::init); + } + + protected void init(CoordinateSystem system) { + coordinateSystem = system; + if (position >= 0 && position < coordinateSystem.getPairs().size()) { + b = coordinateSystem.getPairs().get(position).getBlh().getLatitude(); + l = coordinateSystem.getPairs().get(position).getBlh().getLongitude(); + h = coordinateSystem.getPairs().get(position).getBlh().getAltitude(); + x = coordinateSystem.getPairs().get(position).getCoordinate().getX(); + y = coordinateSystem.getPairs().get(position).getCoordinate().getY(); + z = coordinateSystem.getPairs().get(position).getCoordinate().getZ(); + met_b.setText(Util.radianToDmsDoubleString(Math.toRadians(b), 6, false)); + met_l.setText(Util.radianToDmsDoubleString(Math.toRadians(l), 6, false)); + met_h.setText(Util.formatDouble2StringDotAuto(h)); + met_name.setText(coordinateSystem.getPairs().get(position).getName()); + met_x.setText(Util.formatDouble2StringDotAuto(x)); + met_y.setText(Util.formatDouble2StringDotAuto(y)); + met_z.setText(Util.formatDouble2StringDotAuto(z)); + mCheckUseH.setChecked(coordinateSystem.getPairs().get(position).isUseH()); + mCheckUseV.setChecked(coordinateSystem.getPairs().get(position).isUseV()); + } + } + + @Override + protected void initData() { + + } + + protected final void onPicked(double b, double l, double h) { + met_b.setText(Util.radianToDmsDoubleString(Math.toRadians(b), 6, false)); + met_l.setText(Util.radianToDmsDoubleString(Math.toRadians(l), 6, false)); + met_h.setText(Util.formatDouble2StringDotAuto(h)); + ToastUtils.showShort(Rstring.open_point_successful()); + } + + final protected void onPicked(String name, double x, double y, double z) { + if (name != null) met_name.setText(name); + met_x.setText(Util.formatDouble2StringDotAuto(x)); + met_y.setText(Util.formatDouble2StringDotAuto(y)); + met_z.setText(Util.formatDouble2StringDotAuto(z)); + ToastUtils.showShort(Rstring.open_point_successful()); + } + + private boolean checkActionEnable() { + if (!mCheckUseH.isChecked() && !mCheckUseV.isChecked()) { + ToastUtils.showShort(Rstring.use_horizontal_or_use_vertical_must_check_at_least_one()); + return false; + } + boolean check_empty_b, check_empty_l, check_empty_h, check_empty_x, check_empty_y, check_empty_z; + String b_text = met_b.getText().toString().trim(); + String l_text = met_l.getText().toString().trim(); + String h_text = met_h.getText().toString().trim(); + String x_text = met_x.getText().toString().trim(); + String y_text = met_y.getText().toString().trim(); + String z_text = met_z.getText().toString().trim(); + + check_empty_b = !"".equals(b_text) && !"-".equals(b_text) && !"+".equals(b_text) && !".".equals(b_text) && !"-.".equals(b_text) && !"+.".equals(b_text); + if (check_empty_b) { + try { + double b = Math.toDegrees(Util.dmsStringToRadian(met_b.getText().toString(), false)); + if (b < -90 || b > 90) { + met_b.setError(getString(Rstring.latitude_invalid())); + check_empty_b = false; + } else { + met_b.setError(null); + check_empty_b = true; + } + } catch (NumberFormatException ex) { + check_empty_b = false; + met_b.setError(getString(Rstring.latitude_invalid())); + } + } else { + met_b.setError(getString(Rstring.illegal_value())); + } + check_empty_l = !"".equals(l_text) && !"-".equals(l_text) && !"+".equals(l_text) && !".".equals(l_text) && !"-.".equals(l_text) && !"+.".equals(l_text); + if (check_empty_l) { + try { + double l = Math.toDegrees(Util.dmsStringToRadian(met_l.getText().toString(), false)); + if (l < -180 || l > 180) { + met_l.setError(getString(Rstring.longitude_invalid())); + check_empty_l = false; + } else { + met_l.setError(null); + check_empty_l = true; + } + } catch (NumberFormatException ex) { + met_l.setError(getString(Rstring.longitude_invalid())); + check_empty_l = false; + } + } else { + met_l.setError(getString(Rstring.illegal_value())); + } + + check_empty_h = !"".equals(h_text) && !"-".equals(h_text) && !"+".equals(h_text) && !".".equals(h_text) && !"-.".equals(h_text) && !"+.".equals(h_text); + if (check_empty_h) { + met_h.setError(null); + } else { + met_h.setError(getString(Rstring.illegal_value())); + } + check_empty_x = !"".equals(x_text) && !"-".equals(x_text) && !"+".equals(x_text) && !".".equals(x_text) && !"-.".equals(x_text) && !"+.".equals(x_text); + if (check_empty_x) { + met_x.setError(null); + } else { + met_x.setError(getString(Rstring.input_illegal())); + } + check_empty_y = !"".equals(y_text) && !"-".equals(y_text) && !"+".equals(y_text) && !".".equals(y_text) && !"-.".equals(y_text) && !"+.".equals(y_text); + if (check_empty_y) { + met_y.setError(null); + } else { + met_y.setError(getString(Rstring.input_illegal())); + } + check_empty_z = !"".equals(z_text) && !"-".equals(z_text) && !"+".equals(z_text) && !".".equals(z_text) && !"-.".equals(z_text) && !"+.".equals(z_text); + if (check_empty_z) { + met_z.setError(null); + } else { + met_z.setError(getString(Rstring.input_illegal())); + } + + return check_empty_b && check_empty_l && check_empty_h && check_empty_x && check_empty_y && check_empty_z; + } + + private void initMaterialEditTextColor() { + if (/*((App) Utils.getApp()).*/isThemeDark()) { + met_b.setMetTextColor(Color.WHITE); + met_l.setMetTextColor(Color.WHITE); + met_h.setMetTextColor(Color.WHITE); + met_name.setMetTextColor(Color.WHITE); + met_x.setMetTextColor(Color.WHITE); + met_y.setMetTextColor(Color.WHITE); + met_z.setMetTextColor(Color.WHITE); + + met_b.setPrimaryColor(Color.LTGRAY); + met_l.setPrimaryColor(Color.LTGRAY); + met_h.setPrimaryColor(Color.LTGRAY); + met_name.setPrimaryColor(Color.LTGRAY); + met_x.setPrimaryColor(Color.LTGRAY); + met_y.setPrimaryColor(Color.LTGRAY); + met_z.setPrimaryColor(Color.LTGRAY); + + met_b.setFocusFraction(1.0f); + met_l.setFocusFraction(1.0f); + met_h.setFocusFraction(1.0f); + met_name.setFocusFraction(1.0f); + met_x.setFocusFraction(1.0f); + met_y.setFocusFraction(1.0f); + met_z.setFocusFraction(1.0f); + + met_b.setMetHintTextColor(Color.GRAY); + met_l.setMetHintTextColor(Color.GRAY); + met_h.setMetHintTextColor(Color.GRAY); + met_name.setMetHintTextColor(Color.GRAY); + met_x.setMetHintTextColor(Color.GRAY); + met_y.setMetHintTextColor(Color.GRAY); + met_z.setMetHintTextColor(Color.GRAY); + + met_b.setUnderlineColor(Color.GRAY); + met_l.setUnderlineColor(Color.GRAY); + met_h.setUnderlineColor(Color.GRAY); + met_name.setUnderlineColor(Color.GRAY); + met_x.setUnderlineColor(Color.GRAY); + met_y.setUnderlineColor(Color.GRAY); + met_z.setUnderlineColor(Color.GRAY); + } + } + + /** + * 处理仪器传回的数据 + */ + public void dealReceivedBLH(Blh blh) { + if (mTimes >= 0 && mTimes < 10) { + mSumB += blh.getLatitude(); + mSumL += blh.getLongitude(); + mSumH += blh.getAltitude(); + mTimes++; + progressBar.setProgress(mTimes); + if (mTimes == 10) { + b = mSumB / mTimes; + l = mSumL / mTimes; + h = mSumH / mTimes; + met_b.setText(Util.radianToDmsDoubleString(Math.toRadians(b), 6, false)); + met_l.setText(Util.radianToDmsDoubleString(Math.toRadians(l), 6, false)); + met_h.setText(Util.formatDouble2StringDotAuto(h)); + } + } + } + + @Override + public void updateRtkPosition(boolean isTiltValid, Blh blh, Blh originalBlh, Coordinate coordinate) { + if (Device.getInstance().isRtkRunning) { + dealReceivedBLH(blh); + } + } + + + /////////////////////// + protected abstract void selectBLH(); + + protected abstract void selectXYZ(); + + protected abstract boolean isThemeDark(); + + @WorkerThread + protected abstract void save(CoordinateSystem coordinateSystem); + + protected abstract void loadCurrentCoordinateSystem(IOnSingleGetCallback callback); +} diff --git a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/AbstractRtkPointCorrectActivity.java b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/AbstractRtkPointCorrectActivity.java new file mode 100644 index 0000000..557a011 --- /dev/null +++ b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/AbstractRtkPointCorrectActivity.java @@ -0,0 +1,654 @@ +package com.project.survey.ui.instrument.mobilestationmode.base; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.os.Bundle; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; + +import androidx.annotation.WorkerThread; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; +import com.bingce.coordlib.enums.DatumEnum; +import com.bingce.coordlib.enums.GridEnum; +import com.bingce.coordlib.enums.HFittingEnum; +import com.bingce.coordlib.model.Blh; +import com.bingce.coordlib.model.BlhCoordinatePair; +import com.bingce.coordlib.model.Coordinate; +import com.bingce.coordlib.model.CoordinateSystem; +import com.bingce.coordlib.model.FourParaResult; +import com.bingce.coordlib.model.HFitParaResult; +import com.bingce.coordlib.model.PlaneTgoParaResult; +import com.bingce.coordlib.model.SevenParaResult; +import com.bingce.coordlib.proj4j.InvalidValueException; +import com.bingce.coordlib.proj4j.ProjectionException; +import com.bingce.coordlib.util.CoorConverter; +import com.bingce.device.ui.DividerItemDecoration; +import com.bingce.device.ui.adapter.AbstractMatchingPointRecyclerViewAdapter; +import com.bingce.device.ui.coordinatesystem.event.UpdateCoordinateSystemEvent; +import com.bingce.utils.IOnSingleGetCallback; +import com.bingce.utils.ThreadPoolUtil; +import com.bingce.utils.Util; + +import org.greenrobot.eventbus.EventBus; +import org.polaric.colorful.ColorfulActivity; + +import blankj.utilcode.util.AppUtils; +import blankj.utilcode.util.ToastUtils; +import device.ui.Rdrawable; +import device.ui.Rid; +import device.ui.Rlayout; +import device.ui.Rstring; + +public abstract class AbstractRtkPointCorrectActivity extends ColorfulActivity { + Toolbar mToolbar; + Spinner mTransMethodSpinner; + Spinner mFitMethodSpinner; + RecyclerView mRecyclerView; + Button mBtnNew; + Button mBtnCalc; + View layout_fit; + + private final int REQUEST_NEW_MATCHING_POINT = 100; + private RecyclerView.Adapter mAdapter; + private CoordinateSystem coordinateSystem; + private int from = -1; + + @SuppressLint("SourceLockedOrientationActivity") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(Rlayout.activity_point_correct()); + bindView(); + setSupportActionBar(mToolbar); + if (getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + // Layout Managers: + mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); + + // Item Decorator: + mRecyclerView.addItemDecoration(new DividerItemDecoration(ContextCompat.getDrawable(this, Rdrawable.list_divider()))); +// mRecyclerView.setItemAnimator(new FadeInLeftAnimator()); + + //如果准备好后初始化UI +// cachedCoordinateSystem.observe(new AbstractCachedObserver() { +// @Override +// public void onChanged(boolean isFirstTimeDataChanged, CoordinateSystem cs) { +// if (coordinateSystem == null) { +// init(cs); +// } +// coordinateSystem = cs; +// +// //监听坐标系变化,及时更新数据 +// mAdapter = new MatchingPointRecyclerViewAdapter(RtkPointCorrectActivity.this, coordinateSystem); +// mRecyclerView.setAdapter(mAdapter); +// } +// }); + observeCurrentCoordinate(instance -> { + if (coordinateSystem == null) { + init(instance); + } + coordinateSystem = instance; + + //监听坐标系变化,及时更新数据 + mAdapter = newMatchingPointRecyclerViewAdapter(this, coordinateSystem); + mRecyclerView.setAdapter(mAdapter); + }); + } + + private void init(CoordinateSystem system) { + coordinateSystem = system; + mTransMethodSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, + new String[]{getString(Rstring.tgo_method()), getString(Rstring.four_parameters()), getString(Rstring.seven_parameters()), getString(Rstring.seven_parameters_strict())})); + mFitMethodSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, + new String[]{getString(Rstring.fixed_correction()), getString(Rstring.plane_fitting()), getString(Rstring.surface_fitting()), getString(Rstring.tgo_fitting())})); + switch (coordinateSystem.hFitting) { + case FIX: + mFitMethodSpinner.setSelection(0); + break; + case PLANE: + mFitMethodSpinner.setSelection(1); + break; + case CURVE: + mFitMethodSpinner.setSelection(2); + break; + default://TGO + mFitMethodSpinner.setSelection(3); + } + + mTransMethodSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + switch (position) { + case 0: + case 1: + layout_fit.setVisibility(View.VISIBLE); + break; + case 2: + case 3: + layout_fit.setVisibility(View.GONE); + break; + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + if (coordinateSystem.grid != GridEnum.NULL) { + switch (coordinateSystem.grid) { + case FOUR_PARA: + mTransMethodSpinner.setSelection(1); + break; + default: + mTransMethodSpinner.setSelection(0); + } + } else if (coordinateSystem.datum != DatumEnum.NULL) { + if (coordinateSystem.datum == DatumEnum.STRICT) { + mTransMethodSpinner.setSelection(3); + + } else { + mTransMethodSpinner.setSelection(2); + } + } else { + mTransMethodSpinner.setSelection(0); + } + + mBtnNew.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { +// Intent intent = new Intent(RtkPointCorrectActivity.this, RtkMatchingPointsActivity.class); +// startActivityForResult(intent, REQUEST_NEW_MATCHING_POINT); + startRtkMatchingPointsActivityForResult(REQUEST_NEW_MATCHING_POINT); + } + }); + mBtnCalc.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mTransMethodSpinner.getSelectedItemPosition() == 0) { + calcPlaneTgoParas(); + } else if (mTransMethodSpinner.getSelectedItemPosition() == 1) { + try { + calcFourParas(); + } catch (ProjectionException exception) { + exception.printStackTrace(); + ToastUtils.showShort(getString(Rstring.illegal_value())); + } + } else { + try { + calcSevenParameters(); + } catch (InvalidValueException exception) { + exception.printStackTrace(); + ToastUtils.showShort(getString(Rstring.illegal_value()) + ":" + exception.getMessage()); + } + } + } + }); + //debug填充数据便于测试 + mBtnNew.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + if (AppUtils.isAppDebug()) { + coordinateSystem.getPairs().clear(); + coordinateSystem.getPairs().add(new BlhCoordinatePair("", new Blh(Math.toDegrees(Util.dmsDoubleToRadian(29.2222341657)), Math.toDegrees(Util.dmsDoubleToRadian(116.0450543619)), -65.3234), new Coordinate(3250655.977, 507769.985, 49.082))); + coordinateSystem.getPairs().add(new BlhCoordinatePair("", new Blh(Math.toDegrees(Util.dmsDoubleToRadian(29.2208211327)), Math.toDegrees(Util.dmsDoubleToRadian(116.0452386143)), -74.3303), new Coordinate(3250220.9412, 507819.9756, 40.086))); + coordinateSystem.getPairs().add(new BlhCoordinatePair("", new Blh(Math.toDegrees(Util.dmsDoubleToRadian(29.2100500849)), Math.toDegrees(Util.dmsDoubleToRadian(116.0127564674)), -80.0736), new Coordinate(3248133.6936, 502296.3579, 34.57))); + mAdapter.notifyDataSetChanged(); + ThreadPoolUtil.execute(() -> { +// ProjectDb.getInstance().updateCurrentCoordinator(coordinateSystem); + save(coordinateSystem); + }); + } + return true; + } + }); + + from = getIntent().getIntExtra("from", -1); + switch (from) { + case 1: + getSupportActionBar().setTitle(Rstring.parameter_calc()); + break; + case 4: + mTransMethodSpinner.setSelection(1); + mTransMethodSpinner.setEnabled(false); + getSupportActionBar().setTitle(Rstring.parameter_calc()); + break; + case 7: + mTransMethodSpinner.setSelection(2); + mTransMethodSpinner.setEnabled(false); + getSupportActionBar().setTitle(Rstring.parameter_calc()); + break; + } + if (from != 1) + new MaterialDialog.Builder(this) + .title(Rstring.hint()) + .content(Rstring.seven_or_four_para_hint()) + .positiveText(Rstring.go_to_config()) + .onPositive((dialog, which) -> { +// BingCeCoordinateSystemActivity.skip2ProjViewAndModifyCurrentCoordinateSystem(this); + skip2ProjViewAndModifyCurrentCoordinateSystem(); + }) + .negativeText(Rstring.configured()) + .show(); + } + + private void calcPlaneTgoParas() { + int useH = 0, useV = 0; + for (int i = 0; i < coordinateSystem.getPairs().size(); i++) { + if (coordinateSystem.getPairs().get(i).isUseH()) + useH++; + if (coordinateSystem.getPairs().get(i).isUseV()) + useV++; + } + if (useH < 1) { + ToastUtils.showShort(Rstring.tgo_parameters_at_least_need_one_hor_matching_point()); + return; + } + switch (mFitMethodSpinner.getSelectedItemPosition()) { + case 0: + coordinateSystem.hFitting = HFittingEnum.FIX; + if (useV < 1) { + ToastUtils.showShort(Rstring.height_fix_fitting_at_least_need_one_vertical_matching_point()); + return; + } + break; + case 1: + coordinateSystem.hFitting = HFittingEnum.PLANE; + if (useV < 3) { + ToastUtils.showShort(Rstring.height_plane_fitting_at_least_need_three_vertical_matching_points()); + return; + } + break; + case 2: + coordinateSystem.hFitting = HFittingEnum.CURVE; + if (useV < 6) { + ToastUtils.showShort(Rstring.height_curve_fitting_at_least_need_six_vertical_matching_points()); + return; + } + break; + default: + coordinateSystem.hFitting = HFittingEnum.TGO; + if (useV < 1) { + ToastUtils.showShort(Rstring.height_tgo_fitting_at_least_need_one_vertical_matching_point()); + return; + } + } + PlaneTgoParaResult planeResult = CoorConverter.calcPlaneTgoPara(coordinateSystem, coordinateSystem.getPairs()); + HFitParaResult hFitResult = CoorConverter.calcHFittingPara(coordinateSystem, coordinateSystem.getPairs()); + if (planeResult != null && hFitResult != null) { + String tgoResultStr = getString(Rstring.tgo_parameters()) + "\n" + + getString(Rstring.tgo_parameters_basex()) + ":" + Util.formatDouble2String(planeResult.getBaseX(), 6) + "\n" + + getString(Rstring.tgo_parameters_basey()) + ":" + Util.formatDouble2String(planeResult.getBaseY(), 6) + "\n" + + getString(Rstring.tgo_parameters_dx()) + ":" + Util.formatDouble2String(planeResult.getDx(), 6) + "\n" + + getString(Rstring.tgo_parameters_dy()) + ":" + Util.formatDouble2String(planeResult.getDy(), 6) + "\n" + + getString(Rstring.tgo_parameters_rotate()) + ":" + Util.radianToDmsString(planeResult.getRotate(), 6, false) + "\n" + + getString(Rstring.tgo_parameters_k()) + ":" + Util.formatDouble2String(planeResult.getScale(), 18); + String fittingResultStr = getString(Rstring.elevation_fitting()) + "\n"; + if (hFitResult.gethFitType() == HFittingEnum.TGO) {//TGO高程拟合 + fittingResultStr += "北原点:" + Util.formatDouble2String(hFitResult.gethFitNorthOrigin(), 4) + "\n" + + "东原点:" + Util.formatDouble2String(hFitResult.gethFitEastOrigin(), 4) + "\n" + + "北斜坡(ppm):" + Util.formatDouble2String(hFitResult.gethFitNorthSlope(), 10) + "\n" + + "东斜坡(ppm):" + Util.formatDouble2String(hFitResult.gethFitEastSlope(), 10) + "\n" + + "高差常量:" + Util.formatDouble2String(hFitResult.gethFitHdConstant(), 4) + "\n"; + } else { + fittingResultStr += "A0:" + Util.formatDouble2String(hFitResult.gethFitA0(), 6) + "\n" + + "A1:" + Util.formatDouble2String(hFitResult.gethFitA1(), 10) + "\n" + + "A2:" + Util.formatDouble2String(hFitResult.gethFitA2(), 10) + "\n" + + "A3:" + Util.formatDouble2String(hFitResult.gethFitA3(), 15) + "\n" + + "A4:" + Util.formatDouble2String(hFitResult.gethFitA4(), 15) + "\n" + + "A5:" + Util.formatDouble2String(hFitResult.gethFitA5(), 15) + "\n" + + getString(Rstring.elevation_fitting_base_n()) + ":" + Util.formatDouble2String(hFitResult.gethFitN(), 6) + "\n" + + getString(Rstring.elevation_fitting_base_e()) + ":" + Util.formatDouble2String(hFitResult.gethFitE(), 6); + } + + StringBuilder residualString = new StringBuilder(getString(Rstring.residual()) + "(" + getString(Rstring.unit()) + ":m):\n"); + for (int i = 0; i < planeResult.getRmsList().size(); i++) { + if (planeResult.getRmsList().get(i) == null && hFitResult.getRmsList().get(i) == null) + continue; + residualString.append(getString(Rstring.zh_di())).append(i + 1) + .append(getString(Rstring.row_point())).append(":\n"); + if (planeResult.getRmsList().get(i) != null) { + double residualPlan = Math.sqrt(Math.pow(planeResult.getRmsList().get(i).getX(), 2) + Math.pow(planeResult.getRmsList().get(i).getY(), 2)); + residualString.append(getString(Rstring.transverse_residual())) + .append("=") + .append(Util.formatDouble2StringDotAuto(residualPlan)) + .append(residualPlan > 0.05 ? "(" + getString(Rstring.residual_overrun()) + ")\n" : "\n"); + } + if (hFitResult.getRmsList().get(i) != null) { + residualString.append(getString(Rstring.vertical_residual())).append("=") + .append(Util.formatDouble2StringDotAuto(hFitResult.getRmsList().get(i).getX())) + .append(Math.abs(hFitResult.getRmsList().get(i).getX()) > 0.05 ? "(" + getString(Rstring.residual_overrun()) + ")\n" : "\n"); + } + } + + new MaterialDialog.Builder(this) + .title(Rstring.tgo_parameters_elevation_fitting_result()) + .content(tgoResultStr + "\n" + fittingResultStr + "\n" + residualString + "\n" + + (planeResult.getRmsList().size() == 2 ? getString(Rstring.point_pair_number_is_better_more_than_two()) : "")) + .positiveText(Rstring.global_apply()) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(MaterialDialog dialog, DialogAction which) { + coordinateSystem.useRtcm = false; + coordinateSystem.datum = DatumEnum.NULL; + coordinateSystem.grid = GridEnum.TGO; + coordinateSystem.tgoBaseX = planeResult.getBaseX(); + coordinateSystem.tgoBaseY = planeResult.getBaseY(); + coordinateSystem.tgoDx = planeResult.getDx(); + coordinateSystem.tgoDy = planeResult.getDy(); + coordinateSystem.tgoRot = Util.radianToDmsDouble(planeResult.getRotate(), false); + coordinateSystem.tgoScl = planeResult.getScale(); + if (hFitResult.gethFitType() == HFittingEnum.TGO) { + coordinateSystem.hFitNorthOrigin = hFitResult.gethFitNorthOrigin(); + coordinateSystem.hFitEastOrigin = hFitResult.gethFitEastOrigin(); + coordinateSystem.hFitNorthSlope = hFitResult.gethFitNorthSlope(); + coordinateSystem.hFitEastSlope = hFitResult.gethFitEastSlope(); + coordinateSystem.hFitHdConstant = hFitResult.gethFitHdConstant(); + } else { + coordinateSystem.hFitA0 = hFitResult.gethFitA0(); + coordinateSystem.hFitA1 = hFitResult.gethFitA1(); + coordinateSystem.hFitA2 = hFitResult.gethFitA2(); + coordinateSystem.hFitA3 = hFitResult.gethFitA3(); + coordinateSystem.hFitA4 = hFitResult.gethFitA4(); + coordinateSystem.hFitA5 = hFitResult.gethFitA5(); + coordinateSystem.hFitN = hFitResult.gethFitN(); + coordinateSystem.hFitE = hFitResult.gethFitE(); + } + coordinateSystem.correctN = 0; + coordinateSystem.correctE = 0; + coordinateSystem.correctH = 0; + ThreadPoolUtil.execute(() -> { +// ProjectDb.getInstance().updateCurrentCoordinator(coordinateSystem); + save(coordinateSystem); + runOnUiThread(() -> { + ToastUtils.showShort(Rstring.apply_success()); + if (from == 1) { + EventBus.getDefault().post(new UpdateCoordinateSystemEvent()); + setResult(RESULT_OK); + finish(); + } + }); + }); + } + }) + .negativeText(Rstring.close()) + .show(); + } else { + ToastUtils.showShort(Rstring.transform_fail()); + } + } + + private void calcFourParas() { + int useH = 0, useV = 0; + for (int i = 0; i < coordinateSystem.getPairs().size(); i++) { + if (coordinateSystem.getPairs().get(i).isUseH()) + useH++; + if (coordinateSystem.getPairs().get(i).isUseV()) + useV++; + } + if (useH < 1) { + ToastUtils.showShort(Rstring.four_parameters_at_least_need_one_matching_point()); + return; + } + switch (mFitMethodSpinner.getSelectedItemPosition()) { + case 0: + coordinateSystem.hFitting = HFittingEnum.FIX; + if (useV < 1) { + ToastUtils.showShort(Rstring.height_fix_fitting_at_least_need_one_vertical_matching_point()); + return; + } + break; + case 1: + coordinateSystem.hFitting = HFittingEnum.PLANE; + if (useV < 3) { + ToastUtils.showShort(Rstring.height_plane_fitting_at_least_need_three_vertical_matching_points()); + return; + } + break; + case 2: + coordinateSystem.hFitting = HFittingEnum.CURVE; + if (useV < 6) { + ToastUtils.showShort(Rstring.height_curve_fitting_at_least_need_six_vertical_matching_points()); + return; + } + break; + default: + coordinateSystem.hFitting = HFittingEnum.TGO; + if (useV < 1) { + ToastUtils.showShort(Rstring.height_tgo_fitting_at_least_need_one_vertical_matching_point()); + return; + } + } + FourParaResult fourResult = CoorConverter.calc4Para(coordinateSystem, coordinateSystem.getPairs()); + HFitParaResult hFitResult = CoorConverter.calcHFittingPara(coordinateSystem, coordinateSystem.getPairs()); + if (fourResult != null && hFitResult != null) { + String fourResultStr = getString(Rstring.four_parameters()) + "\n" + + getString(Rstring.four_parameters_dx()) + ":" + Util.formatDouble2String(fourResult.getDx(), 6) + "\n" + + getString(Rstring.four_parameters_dy()) + ":" + Util.formatDouble2String(fourResult.getDy(), 6) + "\n" + + getString(Rstring.four_parameters_rotate()) + ":" + Util.radianToDmsString(fourResult.getRotate(), 6, false) + "\n" + + getString(Rstring.four_parameters_k()) + ":" + Util.formatDouble2String(fourResult.getScale(), 18); + String fittingResultStr = getString(Rstring.elevation_fitting()) + "\n"; + if (hFitResult.gethFitType() == HFittingEnum.TGO) {//TGO高程拟合 + fittingResultStr += "北原点:" + Util.formatDouble2String(hFitResult.gethFitNorthOrigin(), 4) + "\n" + + "东原点:" + Util.formatDouble2String(hFitResult.gethFitEastOrigin(), 4) + "\n" + + "北斜坡(ppm):" + Util.formatDouble2String(hFitResult.gethFitNorthSlope(), 10) + "\n" + + "东斜坡(ppm):" + Util.formatDouble2String(hFitResult.gethFitEastSlope(), 10) + "\n" + + "高差常量:" + Util.formatDouble2String(hFitResult.gethFitHdConstant(), 4) + "\n"; + } else { + fittingResultStr += "A0:" + Util.formatDouble2String(hFitResult.gethFitA0(), 6) + "\n" + + "A1:" + Util.formatDouble2String(hFitResult.gethFitA1(), 10) + "\n" + + "A2:" + Util.formatDouble2String(hFitResult.gethFitA2(), 10) + "\n" + + "A3:" + Util.formatDouble2String(hFitResult.gethFitA3(), 15) + "\n" + + "A4:" + Util.formatDouble2String(hFitResult.gethFitA4(), 15) + "\n" + + "A5:" + Util.formatDouble2String(hFitResult.gethFitA5(), 15) + "\n" + + getString(Rstring.elevation_fitting_base_n()) + ":" + Util.formatDouble2String(hFitResult.gethFitN(), 6) + "\n" + + getString(Rstring.elevation_fitting_base_e()) + ":" + Util.formatDouble2String(hFitResult.gethFitE(), 6); + } + StringBuilder residualString = new StringBuilder(getString(Rstring.residual()) + "(" + getString(Rstring.unit()) + ":m):\n"); + for (int i = 0; i < fourResult.getRmsList().size(); i++) { + if (fourResult.getRmsList().get(i) == null && hFitResult.getRmsList().get(i) == null) + continue; + residualString.append(getString(Rstring.zh_di())).append(i + 1) + .append(getString(Rstring.row_point())).append(":\n"); + if (fourResult.getRmsList().get(i) != null) { + double residualPlan = Math.sqrt(Math.pow(fourResult.getRmsList().get(i).getX(), 2) + Math.pow(fourResult.getRmsList().get(i).getY(), 2)); + residualString.append(getString(Rstring.transverse_residual())) + .append("=") + .append(Util.formatDouble2StringDotAuto(residualPlan)) + .append(residualPlan > 0.05 ? "(" + getString(Rstring.residual_overrun()) + ")\n" : "\n"); + } + if (hFitResult.getRmsList().get(i) != null) { + residualString.append(getString(Rstring.vertical_residual())).append("=") + .append(Util.formatDouble2StringDotAuto(hFitResult.getRmsList().get(i).getX())) + .append(Math.abs(hFitResult.getRmsList().get(i).getX()) > 0.05 ? "(" + getString(Rstring.residual_overrun()) + ")\n" : "\n"); + } + } + + new MaterialDialog.Builder(this) + .title(Rstring.four_parameters_elevation_fitting_result()) + .content(fourResultStr + "\n" + fittingResultStr + "\n" + residualString + "\n" + + (fourResult.getRmsList().size() == 2 ? getString(Rstring.point_pair_number_is_better_more_than_two()) : "")) + .positiveText(Rstring.global_apply()) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(MaterialDialog dialog, DialogAction which) { + coordinateSystem.useRtcm = false; + coordinateSystem.datum = DatumEnum.NULL; + coordinateSystem.grid = GridEnum.FOUR_PARA; + coordinateSystem.fourDx = fourResult.getDx(); + coordinateSystem.fourDy = fourResult.getDy(); + coordinateSystem.fourRot = Util.radianToDmsDouble(fourResult.getRotate(), false); + coordinateSystem.fourScl = fourResult.getScale(); + if (hFitResult.gethFitType() == HFittingEnum.TGO) { + coordinateSystem.hFitNorthOrigin = hFitResult.gethFitNorthOrigin(); + coordinateSystem.hFitEastOrigin = hFitResult.gethFitEastOrigin(); + coordinateSystem.hFitNorthSlope = hFitResult.gethFitNorthSlope(); + coordinateSystem.hFitEastSlope = hFitResult.gethFitEastSlope(); + coordinateSystem.hFitHdConstant = hFitResult.gethFitHdConstant(); + } else { + coordinateSystem.hFitA0 = hFitResult.gethFitA0(); + coordinateSystem.hFitA1 = hFitResult.gethFitA1(); + coordinateSystem.hFitA2 = hFitResult.gethFitA2(); + coordinateSystem.hFitA3 = hFitResult.gethFitA3(); + coordinateSystem.hFitA4 = hFitResult.gethFitA4(); + coordinateSystem.hFitA5 = hFitResult.gethFitA5(); + coordinateSystem.hFitN = hFitResult.gethFitN(); + coordinateSystem.hFitE = hFitResult.gethFitE(); + } + coordinateSystem.correctN = 0; + coordinateSystem.correctE = 0; + coordinateSystem.correctH = 0; + ThreadPoolUtil.execute(() -> { +// ProjectDb.getInstance().updateCurrentCoordinator(coordinateSystem); + save(coordinateSystem); + runOnUiThread(() -> { + ToastUtils.showShort(Rstring.apply_success()); + if (from == 1) { + EventBus.getDefault().post(new UpdateCoordinateSystemEvent()); + setResult(RESULT_OK); + finish(); + } + }); + }); + } + }) + .negativeText(Rstring.close()) + .show(); + } else { + ToastUtils.showShort(Rstring.transform_fail()); + } + } + + private void calcSevenParameters() { + int use = 0; + for (int i = 0; i < coordinateSystem.getPairs().size(); i++) { + if (coordinateSystem.getPairs().get(i).isUseH() && coordinateSystem.getPairs().get(i).isUseV()) + use++; + } + if (use < 3) { + ToastUtils.showShort(Rstring.seven_parameters_at_least_need_three_horizontal_vertical_matching_points()); + return; + } + SevenParaResult result = CoorConverter.calc7Para(coordinateSystem, coordinateSystem.getPairs(), mTransMethodSpinner.getSelectedItemPosition() == 3 ? DatumEnum.STRICT : DatumEnum.BURSA); + if (result != null) { + StringBuilder residualString = new StringBuilder(getString(Rstring.residual()) + "(" + getString(Rstring.unit()) + ":m):\n"); + for (int i = 0; i < result.getRmsList().size(); i++) { + double residualX = result.getRmsList().get(i).getX(); + double residualY = result.getRmsList().get(i).getY(); + double residualZ = result.getRmsList().get(i).getZ(); + double residualPlan = Math.sqrt(Math.pow(residualX, 2) + Math.pow(residualY, 2)); + residualString.append(getString(Rstring.zh_di())) + .append(i + 1) + .append(getString(Rstring.row_point())) + .append(":\n") + .append(getString(Rstring.transverse_residual())) + .append("=") + .append(Util.formatDouble2StringDotAuto(residualPlan)) + .append(residualPlan > 0.05 ? "(" + getString(Rstring.residual_overrun()) + ")\n" : "\n") + .append(getString(Rstring.vertical_residual())).append("=") + .append(Util.formatDouble2StringDotAuto(residualZ)) + .append(Math.abs(residualZ) > 0.05 ? "(" + getString(Rstring.residual_overrun()) + ")\n" : "\n"); + } + String sevenResult = getString(Rstring.seven_parameters_dx()) + ":" + Util.formatDouble2String(result.getDx(), 6) + "\n" + + getString(Rstring.seven_parameters_dy()) + ":" + Util.formatDouble2String(result.getDy(), 6) + "\n" + + getString(Rstring.seven_parameters_dz()) + ":" + Util.formatDouble2String(result.getDz(), 6) + "\n" + + getString(Rstring.seven_parameters_rx()) + ":" + Util.formatDouble2String(result.getRx(), 8) + "\n" + + getString(Rstring.seven_parameters_ry()) + ":" + Util.formatDouble2String(result.getRy(), 8) + "\n" + + getString(Rstring.seven_parameters_rz()) + ":" + Util.formatDouble2String(result.getRz(), 8) + "\n" + + getString(Rstring.seven_parameters_ppm()) + ":" + Util.formatDouble2String(result.getPpm(), 8); + + new MaterialDialog.Builder(this) + .title(Rstring.seven_parameters_result()) + .content(sevenResult + "\n" + residualString) + .positiveText(Rstring.global_apply()) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(MaterialDialog dialog, DialogAction which) { + coordinateSystem.useRtcm = false; + coordinateSystem.datum = mTransMethodSpinner.getSelectedItemPosition() == 3 ? DatumEnum.STRICT : DatumEnum.BURSA; + coordinateSystem.grid = GridEnum.NULL; + coordinateSystem.hFitting = HFittingEnum.NULL; + coordinateSystem.sevenDx = result.getDx(); + coordinateSystem.sevenDy = result.getDy(); + coordinateSystem.sevenDz = result.getDz(); + coordinateSystem.sevenRx = result.getRx(); + coordinateSystem.sevenRy = result.getRy(); + coordinateSystem.sevenRz = result.getRz(); + coordinateSystem.sevenPpm = result.getPpm(); + coordinateSystem.correctN = 0; + coordinateSystem.correctE = 0; + coordinateSystem.correctH = 0; + ThreadPoolUtil.execute(() -> { +// ProjectDb.getInstance().updateCurrentCoordinator(coordinateSystem); + save(coordinateSystem); + runOnUiThread(() -> { + ToastUtils.showShort(Rstring.apply_success()); + if (from == 1) { + EventBus.getDefault().post(new UpdateCoordinateSystemEvent()); + setResult(RESULT_OK); + finish(); + } + }); + }); + } + }) + .negativeText(Rstring.close()) + .show(); + + } else { + ToastUtils.showShort(Rstring.transform_fail()); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + } + return super.onOptionsItemSelected(item); + } +// @Override +// protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { +// super.onActivityResult(requestCode, resultCode, data); +// if (requestCode == REQUEST_NEW_MATCHING_POINT && resultCode == RESULT_OK) { +// coordinateSystem = RTK.getInstance().getCoordinateSystem(); +// mAdapter = new MatchingPointRecyclerViewAdapter(this, coordinateSystem.getPairs()); +// mRecyclerView.setAdapter(mAdapter); +// } +// } + + ///////////////////////// + protected void bindView() { + mToolbar = findViewById(Rid.toolbar()); + mTransMethodSpinner = findViewById(Rid.activity_point_correct_spinner_transform_method()); + mFitMethodSpinner = findViewById(Rid.activity_point_correct_spinner_fit_method()); + mRecyclerView = findViewById(Rid.recycler_view_point_correct()); + mBtnNew = findViewById(Rid.activity_point_correct_btn_new_point_pair()); + mBtnCalc = findViewById(Rid.activity_point_correct_btn_calc()); + layout_fit = findViewById(Rid.activity_point_correct_layout_fit_method()); + } + + protected abstract void observeCurrentCoordinate(IOnSingleGetCallback callback); + + protected abstract AbstractMatchingPointRecyclerViewAdapter newMatchingPointRecyclerViewAdapter(Context context, CoordinateSystem coordinateSystem); + + protected abstract void startRtkMatchingPointsActivityForResult(int requestCode); + + protected abstract void skip2ProjViewAndModifyCurrentCoordinateSystem(); + + @WorkerThread + protected abstract void save(CoordinateSystem coordinateSystem); +} diff --git a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkMatchingPointsActivity.java b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkMatchingPointsActivity.java index df9f732..4429661 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkMatchingPointsActivity.java +++ b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkMatchingPointsActivity.java @@ -1,16 +1,10 @@ package com.project.survey.ui.instrument.mobilestationmode.base; import com.afollestad.materialdialogs.MaterialDialog; +import com.bingce.coordlib.enums.EllipsoidEnum; import com.bingce.coordlib.model.CoordinateSystem; -import com.bingce.data.database.DBQueryConstant; -import com.bingce.data.database.KeyValueDb; import com.bingce.data.database.ProjectDb; -import com.bingce.data.surveyor.designdata.project.ProjectConstants; -import com.bingce.data.surveyor.designdata.project.ProjectRecord; -import com.bingce.device.ui.rtk.AbstractRtkMatchingPointsActivity; - import com.bingce.utils.IOnSingleGetCallback; -import com.bingce.utils.ThreadPoolUtil; import com.project.survey.App; import com.project.survey.R; import com.project.survey.ui.instrument.setupstation.BingCeBaseSurveyPresenter; @@ -20,6 +14,7 @@ import com.project.survey.ui.instrument.setupstation.StakingNewJobActivity; import blankj.utilcode.util.Utils; + public class RtkMatchingPointsActivity extends AbstractRtkMatchingPointsActivity { @Override protected void hideSoftKey() { @@ -110,15 +105,20 @@ public class RtkMatchingPointsActivity extends AbstractRtkMatchingPointsActivity @Override protected void loadCurrentCoordinateSystem(IOnSingleGetCallback callback) { - ThreadPoolUtil.execute(() -> { - String currentProjectId = KeyValueDb.currentProjectId(); - ProjectRecord projectRecord = ProjectDb.getInstance() - .rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectId)); - if (projectRecord != null) { - runOnUiThread(() -> { - callback.onGet(projectRecord.coordinateSystem); - }); - } - }); + // TODO: 2024/8/15 获取坐标系 +// ThreadPoolUtil.execute(() -> { +// String currentProjectId = KeyValueDb.currentProjectId(); +// ProjectRecord projectRecord = ProjectDb.getInstance() +// .rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectId)); +// if (projectRecord != null) { +// runOnUiThread(() -> { +// callback.onGet(projectRecord.coordinateSystem); +// }); +// } +// }); + + CoordinateSystem coordinateSystem = new CoordinateSystem("2000"); + coordinateSystem.setEllipsoid(EllipsoidEnum.AGD_84); + callback.onGet(coordinateSystem); } } diff --git a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java index f1f8617..85a025a 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java +++ b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java @@ -5,40 +5,41 @@ import android.content.Intent; import android.view.Menu; import android.view.MenuItem; +import com.bingce.coordlib.enums.EllipsoidEnum; import com.bingce.coordlib.model.CoordinateSystem; -import com.bingce.data.database.DBQueryConstant; -import com.bingce.data.database.KeyValueDb; import com.bingce.data.database.ProjectDb; -import com.bingce.data.surveyor.designdata.project.ProjectConstants; import com.bingce.device.ui.adapter.AbstractMatchingPointRecyclerViewAdapter; -import com.bingce.device.ui.rtk.AbstractRtkPointCorrectActivity; import com.bingce.surveyor.agentweb.HelpWebActivity; import com.bingce.ui.coordinatesystem.BingCeCoordinateSystemActivity; import com.bingce.utils.IOnSingleGetCallback; -import com.bingce.utils.ThreadPoolUtil; import com.project.survey.R; import com.project.survey.ui.instrument.mobilestationmode.adapter.MatchingPointRecyclerViewAdapter; /** - * 点校正 + * 点校正(参数解算) */ public class RtkPointCorrectActivity extends AbstractRtkPointCorrectActivity { @Override protected void observeCurrentCoordinate(IOnSingleGetCallback callback) { - ThreadPoolUtil.execute(() -> { - String currentProjectId = KeyValueDb.currentProjectId(); - runOnUiThread(() -> { - ProjectDb.getInstance().rawQueryLiveData( - DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectId)) - .observe(this, projectRecord -> { - if (projectRecord == null) { - return; - } - callback.onGet(projectRecord.coordinateSystem); - }); - }); - }); + // TODO: 2024/8/15 获取坐标系 +// ThreadPoolUtil.execute(() -> { +// String currentProjectId = KeyValueDb.currentProjectId(); +// runOnUiThread(() -> { +// ProjectDb.getInstance().rawQueryLiveData( +// DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectId)) +// .observe(this, projectRecord -> { +// if (projectRecord == null) { +// return; +// } +// callback.onGet(projectRecord.coordinateSystem); +// }); +// }); +// }); + + CoordinateSystem coordinateSystem = new CoordinateSystem("2000"); + coordinateSystem.setEllipsoid(EllipsoidEnum.AGD_84); + callback.onGet(coordinateSystem); } @Override @@ -64,7 +65,7 @@ public class RtkPointCorrectActivity extends AbstractRtkPointCorrectActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_activity_rtk_point_correct, menu); +// getMenuInflater().inflate(R.menu.menu_activity_rtk_point_correct, menu); return super.onCreateOptionsMenu(menu); }