84 lines
3.7 KiB
C++
84 lines
3.7 KiB
C++
// AppSettings.cpp
|
|||
|
|
#include "AppSettings.h"
|
||
|
|
#include <QFileDialog>
|
||
|
|
#include <QFileInfo>
|
||
|
|
#include <QCoreApplication>
|
||
|
|
#define DEFKEY(name, val) const QString AppSettings::name = QStringLiteral(val)
|
||
|
|
DEFKEY(K_YoloModel, "paths/yoloModel");
|
||
|
|
DEFKEY(K_LeftCal, "paths/leftCal");
|
||
|
|
DEFKEY(K_RightCal, "paths/rightCal");
|
||
|
|
DEFKEY(K_StereoCalDir, "paths/stereoCalDir");
|
||
|
|
DEFKEY(K_CAD, "paths/cad");
|
||
|
|
DEFKEY(K_ShapeModel, "paths/shapeModel"); // 兼容旧版(单模板)
|
||
|
|
DEFKEY(K_ShapeModelLeft, "paths/shapeModelLeft"); // 左相机轮廓库
|
||
|
|
DEFKEY(K_ShapeModelRight, "paths/shapeModelRight"); // 右相机轮廓库
|
||
|
|
DEFKEY(K_ExportDir, "paths/exportDir");
|
||
|
|
DEFKEY(K_Caltab, "paths/caltab");
|
||
|
|
DEFKEY(K_CalibSaveDir, "paths/calibSaveDir");
|
||
|
|
DEFKEY(K_CalibImageDir, "paths/calibImageDir");
|
||
|
|
DEFKEY(K_HandEyeMatrix, "paths/handEyeMatrix");
|
||
|
|
DEFKEY(K_HandEyeSaveDir, "paths/handEyeSaveDir");
|
||
|
|
DEFKEY(K_HandEyeType, "paths/handEyeType");
|
||
|
|
DEFKEY(K_CalibBoardType, "calibration/boardType");
|
||
|
|
DEFKEY(K_CalibFindSigma, "calibration/findSigma");
|
||
|
|
DEFKEY(K_CalibFindAlpha, "calibration/findAlpha");
|
||
|
|
DEFKEY(K_CalibGapTolerance, "calibration/gapTolerance");
|
||
|
|
DEFKEY(K_CalibMaxDiamMarks, "calibration/maxDiamMarks");
|
||
|
|
DEFKEY(K_CalibSkipFindCaltab, "calibration/skipFindCaltab");
|
||
|
|
DEFKEY(K_GraspOffsetZMm, "pose/graspOffsetZMm");
|
||
|
|
DEFKEY(K_LeftCamSN, "camera/leftSN");
|
||
|
|
DEFKEY(K_RightCamSN, "camera/rightSN");
|
||
|
|
DEFKEY(K_BiasEnabled, "bias/enabled");
|
||
|
|
DEFKEY(K_BiasXmm, "bias/x_mm");
|
||
|
|
DEFKEY(K_BiasYmm, "bias/y_mm");
|
||
|
|
DEFKEY(K_BiasZmm, "bias/z_mm");
|
||
|
|
DEFKEY(K_BiasSamples, "bias/validSamples");
|
||
|
|
DEFKEY(K_MetricDistanceCompMm, "metric/distanceCompMm");
|
||
|
|
#undef DEFKEY
|
||
|
|
AppSettings::AppSettings()
|
||
|
|
: m_q(QSettings::IniFormat, QSettings::UserScope,
|
||
|
|
QStringLiteral("StereoVision"), QStringLiteral("StereoVision")) {}
|
||
|
|
AppSettings& AppSettings::instance() { static AppSettings s; return s; }
|
||
|
|
QString AppSettings::get(const QString& k, const QString& fb) const {
|
||
|
|
QString v = m_q.value(k, fb).toString();
|
||
|
|
if (!v.isEmpty() && !QFileInfo::exists(QFileInfo(v).absolutePath())) return fb;
|
||
|
|
return v;
|
||
|
|
}
|
||
|
|
QString AppSettings::getRaw(const QString& k, const QString& fb) const {
|
||
|
|
return m_q.value(k, fb).toString();
|
||
|
|
}
|
||
|
|
bool AppSettings::has(const QString& k) const { return m_q.contains(k); }
|
||
|
|
void AppSettings::set(const QString& k, const QString& v) {
|
||
|
|
if (v.isEmpty()) return; m_q.setValue(k, v); m_q.sync();
|
||
|
|
}
|
||
|
|
static QString startDir(const QString& last) {
|
||
|
|
if (last.isEmpty()) return QCoreApplication::applicationDirPath();
|
||
|
|
QFileInfo fi(last);
|
||
|
|
if (fi.isDir() && fi.exists()) return fi.absoluteFilePath();
|
||
|
|
QString d = fi.absolutePath();
|
||
|
|
return QFileInfo::exists(d) ? d : QCoreApplication::applicationDirPath();
|
||
|
|
}
|
||
|
|
QString AppSettings::openFile(QWidget* w, const QString& k, const QString& t,
|
||
|
|
const QString& f, const QString& fb) {
|
||
|
|
QString last = get(k, fb);
|
||
|
|
QString s = startDir(last);
|
||
|
|
if (!last.isEmpty() && QFileInfo::exists(last)) s = last;
|
||
|
|
QString p = QFileDialog::getOpenFileName(w, t, s, f);
|
||
|
|
if (!p.isEmpty()) set(k, p);
|
||
|
|
return p;
|
||
|
|
}
|
||
|
|
QString AppSettings::saveFile(QWidget* w, const QString& k, const QString& t,
|
||
|
|
const QString& f, const QString& fb) {
|
||
|
|
QString p = QFileDialog::getSaveFileName(w, t, startDir(get(k,fb)), f);
|
||
|
|
if (!p.isEmpty()) set(k, p);
|
||
|
|
return p;
|
||
|
|
}
|
||
|
|
QString AppSettings::openDir(QWidget* w, const QString& k, const QString& t,
|
||
|
|
const QString& fb) {
|
||
|
|
QString last = get(k, fb);
|
||
|
|
QString p = QFileDialog::getExistingDirectory(w, t,
|
||
|
|
last.isEmpty() ? QCoreApplication::applicationDirPath() : last);
|
||
|
|
if (!p.isEmpty()) set(k, p);
|
||
|
|
return p;
|
||
|
|
}
|