From da38a6db8a084b5b64a1c106cf55f920be8c8f1a Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Thu, 21 Nov 2024 11:52:54 -0600 Subject: [PATCH 01/11] Convert old style of connect with new one. Work on solver from vlm more --- src/core/uProbeX.cpp | 86 +++++------------------ src/gstar/AbstractImageWidget.cpp | 67 +++++------------- src/gstar/AnnotationToolBarWidget.cpp | 5 +- src/gstar/AnnotationTreeModel.cpp | 5 +- src/gstar/ImageViewScene.cpp | 3 +- src/mvc/SolverProfileWidget.cpp | 65 ++++++++++------- src/mvc/SolverProfileWidget.h | 12 +++- src/mvc/SolverWidget.cpp | 2 +- src/mvc/SolverWidget.h | 4 +- src/mvc/SpectraWidget.cpp | 3 +- src/mvc/VLM_Widget.cpp | 12 +--- src/preferences/SolverParameterWidget.cpp | 4 +- src/preferences/SolverTable.cpp | 11 ++- src/preferences/SolverTable.h | 2 +- 14 files changed, 102 insertions(+), 179 deletions(-) diff --git a/src/core/uProbeX.cpp b/src/core/uProbeX.cpp index 8211559..6a4f6e1 100644 --- a/src/core/uProbeX.cpp +++ b/src/core/uProbeX.cpp @@ -442,28 +442,13 @@ void uProbeX::make_VLM_Window(VLM_Model* model) VLM_Widget* widget = new VLM_Widget(); widget->resize(1027, 768); widget->setModel(model); - - connect(widget, - SIGNAL(solverStart()), - this, - SLOT(solverStart())); - - connect(widget, - SIGNAL(solverVariableUpdate(double, double)), - this, - SLOT(solverVariableUpdate(double, double))); - - connect(widget, - SIGNAL(cancelSolverVariableUpdate()), - this, - SLOT(cancelSolverVariableUpdate())); - - + /* TODO: connect properly + connect(widget, &VLM_Widget::solverStart, this, &uProbeX::solverStart); + connect(widget, &VLM_Widget::solverVariableUpdate, this, &uProbeX::solverVariableUpdate); + connect(widget, &VLM_Widget::cancelSolverVariableUpdate, this, &uProbeX::cancelSolverVariableUpdate); +*/ SubWindow* w = new SubWindow(m_mdiArea); - connect(w, - SIGNAL(windowClosing(SubWindow*)), - this, - SLOT(subWindowClosed(SubWindow*))); + connect(w, &SubWindow::windowClosing, this, &uProbeX::subWindowClosed); m_mdiArea->addSubWindow(w); @@ -474,10 +459,7 @@ void uProbeX::make_VLM_Window(VLM_Model* model) m_subWindows[w->getUuid()] = w; - connect(w, - SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates )), - widget, - SLOT(windowChanged(Qt::WindowStates, Qt::WindowStates))); + connect(w, &SubWindow::windowStateChanged, widget, &VLM_Widget::windowChanged); } //--------------------------------------------------------------------------- @@ -538,31 +520,16 @@ void uProbeX::make_VLM_Window(QString path, bool newWindow) return; } - connect(widget, - SIGNAL(solverStart()), - this, - SLOT(solverStart())); - - connect(widget, - SIGNAL(solverVariableUpdate(double, double)), - this, - SLOT(solverVariableUpdate(double, double))); - - connect(widget, - SIGNAL(cancelSolverVariableUpdate()), - this, - SLOT(cancelSolverVariableUpdate())); - - + /*TODO: connect properly + connect(widget, &VLM_Widget::solverStart, this, &uProbeX::solverStart); + connect(widget, &VLM_Widget::solverVariableUpdate, this, &uProbeX::solverVariableUpdate); + connect(widget, &VLM_Widget::cancelSolverVariableUpdate, this, &uProbeX::cancelSolverVariableUpdate); + */ SubWindow* w = nullptr; if (newWindow == true) { w = new SubWindow(m_mdiArea); - connect(w, - SIGNAL(windowClosing(SubWindow*)), - this, - SLOT(subWindowClosed(SubWindow*))); - + connect(w, &SubWindow::windowClosing, this, &uProbeX::subWindowClosed); } m_mdiArea->addSubWindow(w); @@ -573,10 +540,7 @@ void uProbeX::make_VLM_Window(QString path, bool newWindow) m_subWindows[w->getUuid()] = w; - connect(w, - SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates)), - widget, - SLOT(windowChanged(Qt::WindowStates, Qt::WindowStates))); + connect(w, &SubWindow::windowStateChanged, widget, &VLM_Widget::windowChanged); } else { @@ -712,10 +676,7 @@ void uProbeX::make_HDF_Window(MapsH5Model* model) SubWindow* w = nullptr; w = new SubWindow(m_mdiArea); - connect(w, - SIGNAL(windowClosing(SubWindow*)), - this, - SLOT(subWindowClosed(SubWindow*))); + connect(w, &SubWindow::windowClosing, this, &uProbeX::subWindowClosed); m_mdiArea->addSubWindow(w); @@ -727,10 +688,7 @@ void uProbeX::make_HDF_Window(MapsH5Model* model) m_subWindows[w->getUuid()] = w; - connect(w, - SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates )), - widget, - SLOT(windowChanged(Qt::WindowStates, Qt::WindowStates))); + connect(w, &SubWindow::windowStateChanged, widget, &MapsElementsWidget::windowChanged); } @@ -744,10 +702,7 @@ void uProbeX::make_MDA_Window(RAW_Model* model) SubWindow* w = nullptr; w = new SubWindow(m_mdiArea); - connect(w, - SIGNAL(windowClosing(SubWindow*)), - this, - SLOT(subWindowClosed(SubWindow*))); + connect(w, &SubWindow::windowClosing, this, &uProbeX::subWindowClosed); m_mdiArea->addSubWindow(w); @@ -759,10 +714,7 @@ void uProbeX::make_MDA_Window(RAW_Model* model) m_subWindows[w->getUuid()] = w; - connect(w, - SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates )), - widget, - SLOT(windowChanged(Qt::WindowStates, Qt::WindowStates))); + //connect(w, &SubWindow::windowStateChanged, widget, &MDA_Widget::windowChanged); } //--------------------------------------------------------------------------- @@ -876,7 +828,7 @@ void uProbeX::openMapsWorkspace(QString dirName) updateRecentMapsWorkspaces(); MapsWorkspaceController* mapsWorkspaceController = new MapsWorkspaceController(this); - connect(mapsWorkspaceController, SIGNAL(controllerClosed(MapsWorkspaceController*)), this, SLOT(mapsControllerClosed(MapsWorkspaceController*))); + connect(mapsWorkspaceController, &MapsWorkspaceController::controllerClosed, this, &uProbeX::mapsControllerClosed); _mapsWorkspaceControllers.append(mapsWorkspaceController); mapsWorkspaceController->setWorkingDir(dirName); diff --git a/src/gstar/AbstractImageWidget.cpp b/src/gstar/AbstractImageWidget.cpp index 3468435..22abf1c 100644 --- a/src/gstar/AbstractImageWidget.cpp +++ b/src/gstar/AbstractImageWidget.cpp @@ -46,14 +46,10 @@ AbstractImageWidget::AbstractImageWidget(int rows, int cols, QWidget* parent) createActions(); - //Setup a QTreeView and AnnotationTreeModel for Annotations m_treeModel = new AnnotationTreeModel(); - connect(m_treeModel, - SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, - SLOT(modelDataChanged(const QModelIndex &, const QModelIndex &))); + connect(m_treeModel, &AnnotationTreeModel::dataChanged, this, &AbstractImageWidget::modelDataChanged); m_selectionModel = new QItemSelectionModel(m_treeModel); @@ -66,23 +62,14 @@ AbstractImageWidget::AbstractImageWidget(int rows, int cols, QWidget* parent) m_annoTreeView->setHeaderHidden(true); m_annoTreeView->setSelectionModel(m_selectionModel); m_annoTreeView->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_annoTreeView, - SIGNAL(customContextMenuRequested(const QPoint &)), - this, - SLOT(treeContextMenu(const QPoint &))); - connect(m_annoTreeView, - SIGNAL(doubleClicked(const QModelIndex &)), - this, - SLOT(treeDoubleClicked(const QModelIndex &))); + connect(m_annoTreeView, &QTreeView::customContextMenuRequested, this, &AbstractImageWidget::treeContextMenu); + connect(m_annoTreeView, &QTreeView::doubleClicked, this, &AbstractImageWidget::treeDoubleClicked); m_imageViewWidget = new ImageViewWidget(rows, cols); m_imageViewWidget->setSceneModel(m_treeModel); m_imageViewWidget->setSceneSelectionModel(m_selectionModel); m_imageViewWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_imageViewWidget, - SIGNAL(customContextMenuRequested(const QPoint &)), - this, - SLOT(viewContextMenu(const QPoint &))); + connect(m_imageViewWidget, &ImageViewWidget::customContextMenuRequested, this, &AbstractImageWidget::viewContextMenu); createAnnotationToolBar(); @@ -177,27 +164,12 @@ void AbstractImageWidget::createActions() m_deleteAction = new QAction("Delete", this); m_showRulerDialogAction = new QAction("Ruler Units", this); - connect(m_addRulerAction, - SIGNAL(triggered()), - this, - SLOT(addRuler())); - connect(m_addMarkerAction, - SIGNAL(triggered()), - this, - SLOT(addMarker())); + connect(m_addRulerAction, &QAction::triggered, this, &AbstractImageWidget::addRuler); + connect(m_addMarkerAction, &QAction::triggered, this, &AbstractImageWidget::addMarker); - connect(m_duplicateAction, - SIGNAL(triggered()), - this, - SLOT(duplicateItem())); - connect(m_deleteAction, - SIGNAL(triggered()), - this, - SLOT(deleteItem())); - connect(m_showRulerDialogAction, - SIGNAL(triggered()), - this, - SLOT(showRulerUnitsDialog())); + connect(m_duplicateAction, &QAction::triggered, this, &AbstractImageWidget::duplicateItem); + connect(m_deleteAction, &QAction::triggered, this, &AbstractImageWidget::deleteItem); + connect(m_showRulerDialogAction, &QAction::triggered, this, &AbstractImageWidget::showRulerUnitsDialog); } @@ -235,19 +207,10 @@ void AbstractImageWidget::createAnnotationToolBar() m_annotationToolbar = new AnnotationToolBarWidget(); - connect(m_annotationToolbar, - SIGNAL(clickRuler()), - this, - SLOT(addRuler())); - connect(m_annotationToolbar, - SIGNAL(clickMarker()), - this, - SLOT(addMarker())); + connect(m_annotationToolbar, &AnnotationToolBarWidget::clickRuler, this, &AbstractImageWidget::addRuler); + connect(m_annotationToolbar, &AnnotationToolBarWidget::clickMarker, this, &AbstractImageWidget::addMarker); - connect(m_annotationToolbar, - SIGNAL(enabledStateChanged(bool)), - this, - SLOT(setAnnotationsEnabled(bool))); + connect(m_annotationToolbar, &AnnotationToolBarWidget::enabledStateChanged, this, &AbstractImageWidget::setAnnotationsEnabled); } @@ -574,9 +537,11 @@ void AbstractImageWidget::setHeightDims(int h) { if (h > (m_imageHeightDim->count() - 1)) return; - disconnect(m_imageHeightDim,SIGNAL(activated(int)),this,SLOT(imageHeightDimChanged(int))); + disconnect(m_imageHeightDim, &QComboBox::activated, this, &AbstractImageWidget::imageHeightDimChanged); + m_imageHeightDim->setCurrentIndex(h); - connect(m_imageHeightDim,SIGNAL(activated(int)),this,SIGNAL(imageHeightDimChanged(int))); + + connect(m_imageHeightDim, &QComboBox::activated, this, &AbstractImageWidget::imageHeightDimChanged); } } diff --git a/src/gstar/AnnotationToolBarWidget.cpp b/src/gstar/AnnotationToolBarWidget.cpp index 45aed27..0fe2aea 100644 --- a/src/gstar/AnnotationToolBarWidget.cpp +++ b/src/gstar/AnnotationToolBarWidget.cpp @@ -76,10 +76,7 @@ AnnotationToolBarWidget::AnnotationToolBarWidget(QWidget* parent) : QLabel* enableLable = new QLabel("Visible:"); m_chkSetVisible = new QCheckBox(); m_chkSetVisible->setChecked(true); - connect(m_chkSetVisible, - SIGNAL(stateChanged(int)), - this, - SLOT(setActionsEnabled(int))); + connect(m_chkSetVisible, &QCheckBox::stateChanged, this, &AnnotationToolBarWidget::setActionsEnabled); m_toolbar->addWidget(enableLable); m_toolbar->addWidget(m_chkSetVisible); diff --git a/src/gstar/AnnotationTreeModel.cpp b/src/gstar/AnnotationTreeModel.cpp index af96098..e113bf6 100644 --- a/src/gstar/AnnotationTreeModel.cpp +++ b/src/gstar/AnnotationTreeModel.cpp @@ -69,10 +69,7 @@ QModelIndex AnnotationTreeModel::appendNode(AbstractGraphicsItem* item) beginInsertRows(gIndex, row, row); - connect(item, - SIGNAL(viewUpdated(AbstractGraphicsItem*)), - this, - SLOT(refreshModel(AbstractGraphicsItem*))); + connect(item, &AbstractGraphicsItem::viewUpdated, this, &AnnotationTreeModel::refreshModel); groupRoot->appendChild(item); diff --git a/src/gstar/ImageViewScene.cpp b/src/gstar/ImageViewScene.cpp index e8e8022..ee52bab 100644 --- a/src/gstar/ImageViewScene.cpp +++ b/src/gstar/ImageViewScene.cpp @@ -43,8 +43,7 @@ ImageViewScene::ImageViewScene(QWidget* parent) : QGraphicsScene(parent) setSceneRect(m_pixItem -> boundingRect()); // Connect selectionChanged signal to annotation slot - connect(this, SIGNAL(selectionChanged()), - this, SLOT(sceneSelectionChanged())); + connect(this, &ImageViewScene::selectionChanged, this, &ImageViewScene::sceneSelectionChanged); } diff --git a/src/mvc/SolverProfileWidget.cpp b/src/mvc/SolverProfileWidget.cpp index 05b52bb..b5446df 100644 --- a/src/mvc/SolverProfileWidget.cpp +++ b/src/mvc/SolverProfileWidget.cpp @@ -12,8 +12,7 @@ #include #include #include - -//#include +#include "solver/NelderMeadSolver.h" //--------------------------------------------------------------------------- @@ -23,7 +22,8 @@ SolverProfileWidget::SolverProfileWidget(QWidget* parent) : QDialog(parent) m_currentProfileIndex = 0; m_coordPoints = nullptr; m_solverWidget = nullptr; - //m_solver = nullptr; + _solver = nullptr; + _transformer = nullptr; createCompontent(); createLayOut(); addDefaultTransformers(); @@ -175,9 +175,6 @@ void SolverProfileWidget::createCompontent() void SolverProfileWidget::addDefaultTransformers() { - SV_CoordTransformer ctrans; - gstar::LinearTransformer ltrans; - LinearCoordTransformer ltrans2; addProfile(QSTR_2IDE_COORD_TRANS, QSTR_2IDE_COORD_TRANS_DESC, ctrans.getAllCoef()); addProfile(QSTR_LINEAR_COORD_TRANS, QSTR_LINEAR_COORD_TRANS_DESC, ltrans.getAllCoef() ); addProfile(QSTR_LINEAR_COORD_TRANS_2, QSTR_LINEAR_COORD_TRANS_DESC_2, ltrans2.getAllCoef() ); @@ -596,6 +593,22 @@ void SolverProfileWidget::switchProfileItem(const QItemSelection& selected, _solverParamWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs()); + switch(m_currentProfileIndex) + { + case 0: + _transformer = &ctrans; + break; + case 1: + _transformer = <rans; + break; + case 2: + _transformer = <rans2; + break; + default: + _transformer = <rans2; + break; + } + } //--------------------------------------------------------------------------- @@ -609,32 +622,32 @@ void SolverProfileWidget::runSolver() emit solverStart(); - /* - if(m_solver == nullptr) + + if(_solver == nullptr) { - m_solver = new PythonSolver(); - if(false == m_solver->initialPythonSolver(m_filePath, m_fileInfo.baseName(), "my_solver")) - { - QMessageBox::warning(nullptr, "Error loading python solver", "Could not load function my_solver() in python script"); - return; - } + + _solver = new NelderMeadSolver(); } - m_solver->setCoordPoints(*m_coordPoints); -*/ + _solver->setTransformer(_transformer); + + _solver->setCoordPoints(*m_coordPoints); + QMap newMinCoefs; QMap minCoefs = _solverParamWidget->getSelectedCoefficientAttrsMap(); -/* - m_solver->setAllCoef(_solverParamWidget->getCoefficientAttrsMap()); - m_solver->setOptions(_solverParamWidget->getOptionAttrsMap()); - m_solver->setMinCoef(minCoefs); -*/ + _solver->setAllCoef(_solverParamWidget->getCoefficientAttrsMap()); + _solver->setOptions(_solverParamWidget->getOptionAttrsMap()); + _solver->setMinCoef(minCoefs); QApplication::setOverrideCursor(Qt::WaitCursor); - // bool retVal = m_solver->run(); + bool retVal = _solver->run(); QApplication::restoreOverrideCursor(); + if (retVal == false) + { + qDebug()<<"Solver failed\n"; + } if(m_solverWidget != nullptr) delete m_solverWidget; m_solverWidget = nullptr; @@ -650,10 +663,10 @@ void SolverProfileWidget::runSolver() this, SLOT(cancelUpdatedSolverVariables())); -// newMinCoefs = m_solver->getMinCoef(); + newMinCoefs = _solver->getMinCoef(); m_solverWidget->setCoefs(minCoefs, newMinCoefs); - // m_solverWidget->setStatusString(m_solver->getLastErrorMessage()); -/* + m_solverWidget->setStatusString(_solver->getLastErrorMessage()); + if(retVal) { m_solverWidget->setUseBtnEnabled(true); @@ -662,7 +675,7 @@ void SolverProfileWidget::runSolver() { m_solverWidget->setUseBtnEnabled(false); } -*/ + m_solverWidget->show(); } diff --git a/src/mvc/SolverProfileWidget.h b/src/mvc/SolverProfileWidget.h index 3204bee..9f85a4d 100644 --- a/src/mvc/SolverProfileWidget.h +++ b/src/mvc/SolverProfileWidget.h @@ -20,7 +20,7 @@ #include #include #include -//#include +#include #include #include #include @@ -240,7 +240,9 @@ private slots: SolverParameterWidget* _solverParamWidget; - //PythonSolver *m_solver; + AbstractSolver* _solver; + + gstar::ITransformer* _transformer; QList< QMap > *m_coordPoints; @@ -248,6 +250,12 @@ private slots: int m_currentProfileIndex; + SV_CoordTransformer ctrans; + + gstar::LinearTransformer ltrans; + + LinearCoordTransformer ltrans2; + }; //--------------------------------------------------------------------------- diff --git a/src/mvc/SolverWidget.cpp b/src/mvc/SolverWidget.cpp index 9db737f..e914772 100644 --- a/src/mvc/SolverWidget.cpp +++ b/src/mvc/SolverWidget.cpp @@ -19,7 +19,7 @@ //--------------------------------------------------------------------------- -SolverWidget::SolverWidget(QWidget *parent) : QWidget(parent) +SolverWidget::SolverWidget(QWidget *parent) : QDialog(parent) { setWindowModality(Qt::WindowModal); diff --git a/src/mvc/SolverWidget.h b/src/mvc/SolverWidget.h index b51191b..603127a 100644 --- a/src/mvc/SolverWidget.h +++ b/src/mvc/SolverWidget.h @@ -6,7 +6,7 @@ #ifndef SOLVER_WIDGET_H #define SOLVER_WIDGET_H -#include +#include #include #include #include @@ -21,7 +21,7 @@ * */ -class SolverWidget : public QWidget +class SolverWidget : public QDialog { Q_OBJECT diff --git a/src/mvc/SpectraWidget.cpp b/src/mvc/SpectraWidget.cpp index bfa5569..7d329e4 100644 --- a/src/mvc/SpectraWidget.cpp +++ b/src/mvc/SpectraWidget.cpp @@ -519,7 +519,8 @@ void SpectraWidget::set_element_lines(data_struct::Fit_Element_Map* elem float line_height = 1.0; if (_display_log10) { - line_height = pow(10.0, (log10(line_max) * line_ratio) ); + //line_height = pow(10.0, (log10(line_max) * line_ratio) ); + line_height = line_max * line_ratio; } else { diff --git a/src/mvc/VLM_Widget.cpp b/src/mvc/VLM_Widget.cpp index 158db6f..96834c0 100644 --- a/src/mvc/VLM_Widget.cpp +++ b/src/mvc/VLM_Widget.cpp @@ -2120,15 +2120,9 @@ void VLM_Widget::runSolver() m_solverWidget = nullptr; m_solverWidget = new SolverWidget(); - connect(m_solverWidget, - SIGNAL(useUpdatedVariables(const QMap)), - this, - SLOT(useUpdatedSolverVariables(const QMap ))); - - connect(m_solverWidget, - SIGNAL(cancelUpdatedVariables()), - this, - SLOT(cancelUpdatedSolverVariables())); + //connect(m_solverWidget, &SolverWidget::useUpdatedVariables, this, SLOT(useUpdatedSolverVariables) ); + + //connect(m_solverWidget, &SolverWidget::cancelUpdatedVariables), this, SLOT(cancelUpdatedSolverVariables) ); newMinCoefs = m_solver->getMinCoef(); m_solverWidget->setCoefs(minCoefs, newMinCoefs); diff --git a/src/preferences/SolverParameterWidget.cpp b/src/preferences/SolverParameterWidget.cpp index 2c3c23b..95c6218 100644 --- a/src/preferences/SolverParameterWidget.cpp +++ b/src/preferences/SolverParameterWidget.cpp @@ -54,7 +54,7 @@ SolverParameterWidget::~SolverParameterWidget() void SolverParameterWidget::addCoefficientItem(Attribute attr) { - m_coefficientTable -> addItem(attr); + m_coefficientTable -> addItemA(attr); } @@ -75,7 +75,7 @@ void SolverParameterWidget::addCoefficientItems(QList solverAttrs) void SolverParameterWidget::addOptionItem(Attribute attr) { - m_optionTable -> addItem(attr); + m_optionTable -> addItemA(attr); } diff --git a/src/preferences/SolverTable.cpp b/src/preferences/SolverTable.cpp index a695f83..f577874 100644 --- a/src/preferences/SolverTable.cpp +++ b/src/preferences/SolverTable.cpp @@ -71,7 +71,7 @@ void SolverTable::addItem() //--------------------------------------------------------------------------- -void SolverTable::addItem(Attribute attr) +void SolverTable::addItemA(Attribute attr) { // Check valid model @@ -139,17 +139,14 @@ void SolverTable::createComponents() m_solverTable->setAlternatingRowColors(true); m_solverTable->resizeColumnsToContents(); - connect(m_solverModel, - SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), - this, - SLOT(tableDataChanged(const QModelIndex&, const QModelIndex&))); + connect(m_solverModel, &AttributeTableModel::dataChanged, this, &SolverTable::tableDataChanged); // Add button m_btnAdd = new QPushButton; m_btnAdd -> setIcon(QIcon(":images/list-add.png")); m_btnAdd -> setFlat(true); m_btnAdd -> setFixedSize(32, 32); - connect(m_btnAdd, SIGNAL(clicked()), this, SLOT(addItem())); + connect(m_btnAdd, &QPushButton::pressed, this, &SolverTable::addItem); // Remove button m_btnRemove = new QPushButton; @@ -159,7 +156,7 @@ void SolverTable::createComponents() m_btnRemove->setEnabled(true); m_btnRemove -> setFixedSize(32, 32); - connect(m_btnRemove, SIGNAL(clicked()), this, SLOT(removeItem())); + connect(m_btnRemove, &QPushButton::pressed, this, &SolverTable::removeItem); // Layout for buttons QHBoxLayout* buttonLayout = new QHBoxLayout; diff --git a/src/preferences/SolverTable.h b/src/preferences/SolverTable.h index 3e10d5a..204aa58 100644 --- a/src/preferences/SolverTable.h +++ b/src/preferences/SolverTable.h @@ -56,7 +56,7 @@ class SolverTable * @brief Internal slot to add an item. Called by the add item button. * @param */ - void addItem(Attribute attr); + void addItemA(Attribute attr); /** * @brief clearAll From 620f57678a1f6a52051e75ec87fb634aa038f997 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Mon, 2 Dec 2024 09:56:13 -0600 Subject: [PATCH 02/11] Added batch scan options to ScanRegionDialog. Added ability to remove multiple scans at once --- src/mvc/ScanQueueWidget.cpp | 47 +++++++++++++------ src/mvc/ScanQueueWidget.h | 4 +- src/mvc/ScanRegionDialog.cpp | 89 +++++++++++++++++++++++++++++------- src/mvc/ScanRegionDialog.h | 17 +++++-- 4 files changed, 121 insertions(+), 36 deletions(-) diff --git a/src/mvc/ScanQueueWidget.cpp b/src/mvc/ScanQueueWidget.cpp index fbdd445..35126a1 100644 --- a/src/mvc/ScanQueueWidget.cpp +++ b/src/mvc/ScanQueueWidget.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "core/defines.h" //--------------------------------------------------------------------------- @@ -45,7 +46,7 @@ void ScanQueueWidget::_createLayout() _scan_queue_table_view = new QTableView(); _scan_queue_table_view->setModel(_scan_queue_table_model); _scan_queue_table_view->setSelectionBehavior(QAbstractItemView::SelectRows); - _scan_queue_table_view->setSelectionMode(QAbstractItemView::SingleSelection); + _scan_queue_table_view->setSelectionMode(QAbstractItemView::ContiguousSelection); _scan_queue_table_view->setDragEnabled(true); _scan_queue_table_view->setAcceptDrops(true); _scan_queue_table_view->setDragDropMode(QAbstractItemView::InternalMove); @@ -58,6 +59,12 @@ void ScanQueueWidget::_createLayout() &QTableView::customContextMenuRequested, this, &ScanQueueWidget::scanContextMenu); + + QShortcut* del_shortcut = new QShortcut(QKeySequence(QKeySequence::Delete), _scan_queue_table_view); + connect(del_shortcut, &QShortcut::activated, this, &ScanQueueWidget::on_remove_scan); + + QShortcut* backsp_shortcut = new QShortcut(QKeySequence(QKeySequence::Backspace), _scan_queue_table_view); + connect(backsp_shortcut, &QShortcut::activated, this, &ScanQueueWidget::on_remove_scan); //_scan_queue_table_view->selectionModel() // _scan_queue_table_view->horizontalHeader()->resizeSections(QHeaderView::Interactive); @@ -93,10 +100,6 @@ void ScanQueueWidget::_createLayout() _btn_add_scan = new QPushButton("Add Scan"); connect(_btn_add_scan, &QPushButton::pressed, &_scan_dialog, &ScanRegionDialog::show); - _btn_add_batch_scan = new QPushButton("Add Batch Scan"); - _btn_add_batch_scan->setEnabled(false); - connect(_btn_add_batch_scan, &QPushButton::pressed, &_scan_dialog, &ScanRegionDialog::show); - _btn_set_history = new QPushButton("Set History Location"); connect(_btn_set_history, &QPushButton::pressed, this, &ScanQueueWidget::onSetHistory); @@ -133,7 +136,6 @@ void ScanQueueWidget::_createLayout() grid->addWidget(_btn_open_env,0,3); grid->addWidget(_btn_close_env,0,4); grid->addWidget(_btn_add_scan,0,6); - grid->addWidget(_btn_add_batch_scan,0,7); grid->addWidget(_btn_set_history,0,8); grid->addWidget(_btn_clear_history,0,9); grid->addItem(new QSpacerItem(999,10), 0,10); @@ -167,8 +169,12 @@ void ScanQueueWidget::scanContextMenu(const QPoint& pos) QMenu menu(_scan_queue_table_view); if (_scan_queue_table_view->selectionModel()->hasSelection()) { - menu.addAction(_move_scan_up); - menu.addAction(_move_scan_down); + auto selected = _scan_queue_table_view->selectionModel()->selectedIndexes(); + if(selected.count() == 1) + { + menu.addAction(_move_scan_up); + menu.addAction(_move_scan_down); + } menu.addAction(_remove_scan); QAction* result = menu.exec(_scan_queue_table_view->viewport()->mapToGlobal(pos)); @@ -187,10 +193,13 @@ void ScanQueueWidget::on_move_scan_up() if (_scan_queue_table_view->selectionModel()->hasSelection()) { QModelIndexList selectedIndexes = _scan_queue_table_view->selectionModel()->selectedRows(); - for (int i = selectedIndexes.count() - 1; i >= 0; i--) + if(selectedIndexes.count() == 1) { - QModelIndex index = selectedIndexes[i]; - emit onMoveScanUp(index.row() - _scan_queue_table_model->get_finished_idx()); + for (int i = selectedIndexes.count() - 1; i >= 0; i--) + { + QModelIndex index = selectedIndexes[i]; + emit onMoveScanUp(index.row() - _scan_queue_table_model->get_finished_idx()); + } } } } @@ -202,10 +211,13 @@ void ScanQueueWidget::on_move_scan_down() if (_scan_queue_table_view->selectionModel()->hasSelection()) { QModelIndexList selectedIndexes = _scan_queue_table_view->selectionModel()->selectedRows(); - for (int i = selectedIndexes.count() - 1; i >= 0; i--) + if(selectedIndexes.count() == 1) { - QModelIndex index = selectedIndexes[i]; - emit onMoveScanDown(index.row() - _scan_queue_table_model->get_finished_idx()); + for (int i = selectedIndexes.count() - 1; i >= 0; i--) + { + QModelIndex index = selectedIndexes[i]; + emit onMoveScanDown(index.row() - _scan_queue_table_model->get_finished_idx()); + } } } } @@ -238,6 +250,13 @@ void ScanQueueWidget::on_remove_scan() //--------------------------------------------------------------------------- +void ScanQueueWidget::onQueueKeyPress(QKeyEvent* event) +{ + +} + +//--------------------------------------------------------------------------- + void ScanQueueWidget::updateQueuedItems(std::vector &finished_plans, std::vector &queued_plans, BlueskyPlan &running_plan) { _scan_queue_table_model->setAllData(finished_plans, queued_plans, running_plan); diff --git a/src/mvc/ScanQueueWidget.h b/src/mvc/ScanQueueWidget.h index eaa4238..7fc6a56 100644 --- a/src/mvc/ScanQueueWidget.h +++ b/src/mvc/ScanQueueWidget.h @@ -78,6 +78,8 @@ public slots: void on_remove_scan(); + void onQueueKeyPress(QKeyEvent*); + protected: /** @@ -105,8 +107,6 @@ public slots: QPushButton* _btn_add_scan; - QPushButton* _btn_add_batch_scan; - QPushButton* _btn_set_history; QPushButton* _btn_clear_history; diff --git a/src/mvc/ScanRegionDialog.cpp b/src/mvc/ScanRegionDialog.cpp index be5b386..079077e 100644 --- a/src/mvc/ScanRegionDialog.cpp +++ b/src/mvc/ScanRegionDialog.cpp @@ -42,10 +42,21 @@ void ScanRegionDialog::_createLayout() _scan_options = new QTableView(); _scan_options->setModel(_scan_table_model); - _btn_update = new QPushButton("Update"); + _chk_batch_scan = new QCheckBox("Set Batch Scan"); + connect(_chk_batch_scan, &QCheckBox::checkStateChanged, this, &ScanRegionDialog::onBatchScanChanged); + + _cb_batch_prop = new QComboBox(); + _batch_start = new QLineEdit("Start Value"); + _batch_end = new QLineEdit("End Value"); + _batch_num = new QLineEdit("Number Iter"); + + _cb_batch_prop->setEnabled(false); + _batch_start->setEnabled(false); + _batch_end->setEnabled(false); + _batch_num->setEnabled(false); + _btn_update_and_queue = new QPushButton("Add To Queue"); _btn_cancel = new QPushButton("Cancel"); - connect(_btn_update, &QPushButton::pressed, this, &ScanRegionDialog::onUpdate); connect(_btn_update_and_queue, &QPushButton::pressed, this, &ScanRegionDialog::onUpdateAndQueue); connect(_btn_cancel, &QPushButton::pressed, this, &ScanRegionDialog::close); @@ -59,15 +70,22 @@ void ScanRegionDialog::_createLayout() type_layout->addWidget(new QLabel("Scan Type: ")); type_layout->addWidget(_scan_type); + QHBoxLayout* batch_layout = new QHBoxLayout(); + batch_layout->addWidget(_chk_batch_scan); + batch_layout->addWidget(_cb_batch_prop); + batch_layout->addWidget(_batch_start); + batch_layout->addWidget(_batch_end); + batch_layout->addWidget(_batch_num); + + QHBoxLayout* button_layout = new QHBoxLayout(); - button_layout->addWidget(_btn_update); button_layout->addWidget(_btn_update_and_queue); button_layout->addWidget(_btn_cancel); - main_layout->addItem(name_layout); main_layout->addItem(type_layout); main_layout->addWidget(_scan_options); + main_layout->addItem(batch_layout); main_layout->addItem(button_layout); setLayout(main_layout); @@ -104,20 +122,31 @@ void ScanRegionDialog::updateProps(QList &anno_list) //--------------------------------------------------------------------------- -void ScanRegionDialog::onUpdate() -{ - //emit ScanUpdated(); - close(); -} - -//--------------------------------------------------------------------------- - void ScanRegionDialog::onUpdateAndQueue() { - BlueskyPlan plan; - plan.type = _scan_type->currentText(); - _scan_table_model->getCurrentParams(plan); - emit ScanUpdated(plan); + if(_chk_batch_scan->checkState() == Qt::Checked) + { + float start = _batch_start->text().toFloat(); + float end = _batch_end->text().toFloat(); + int num = _batch_num->text().toInt(); + float inc = ( (end - start) + 1 )/ (float)num; + for(int i=0; icurrentText(); + _scan_table_model->getCurrentParams(plan); + plan.parameters[_cb_batch_prop->currentText()].default_val = QString::number(start); + emit ScanUpdated(plan); + start += inc; + } + } + else + { + BlueskyPlan plan; + plan.type = _scan_type->currentText(); + _scan_table_model->getCurrentParams(plan); + emit ScanUpdated(plan); + } close(); } @@ -130,9 +159,37 @@ void ScanRegionDialog::scanChanged(const QString &scan_name) if(_avail_scans->count(scan_name) > 0) { _scan_table_model->setAllData(_avail_scans->at(scan_name)); + _cb_batch_prop->clear(); + BlueskyPlan plan = _avail_scans->at(scan_name); + for(auto itr : plan.parameters) + { + _cb_batch_prop->addItem(itr.first); + } } } } +//--------------------------------------------------------------------------- + +void ScanRegionDialog::onBatchScanChanged(Qt::CheckState state) +{ + + if(state == Qt::Checked) + { + _cb_batch_prop->setEnabled(true); + _batch_start->setEnabled(true); + _batch_end->setEnabled(true); + _batch_num->setEnabled(true); + + } + else + { + _cb_batch_prop->setEnabled(false); + _batch_start->setEnabled(false); + _batch_end->setEnabled(false); + _batch_num->setEnabled(false); + } +} + //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- diff --git a/src/mvc/ScanRegionDialog.h b/src/mvc/ScanRegionDialog.h index c5b4b0e..d10fec8 100644 --- a/src/mvc/ScanRegionDialog.h +++ b/src/mvc/ScanRegionDialog.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -53,12 +54,12 @@ class ScanRegionDialog : public QDialog public slots: - void onUpdate(); - void onUpdateAndQueue(); void scanChanged(const QString &); + void onBatchScanChanged(Qt::CheckState); + protected: void _createLayout(); @@ -67,8 +68,8 @@ public slots: QLineEdit *_scan_name; QComboBox *_scan_type; - - QPushButton *_btn_update; + + QComboBox *_cb_batch_prop; QPushButton *_btn_update_and_queue; @@ -76,6 +77,14 @@ public slots: QTableView* _scan_options; + QLineEdit *_batch_start; + + QLineEdit *_batch_end; + + QLineEdit *_batch_num; + + QCheckBox* _chk_batch_scan; + ScanTableModel *_scan_table_model; QLabel* _lbl_region_name; From 0736ce9ad5559fdc605c4fc652a418b8ea859f91 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Mon, 2 Dec 2024 12:53:52 -0600 Subject: [PATCH 03/11] Connected light to microprobe coords --- src/core/uProbeX.cpp | 11 +- src/gstar/CoordinateWidget.h | 2 + src/mvc/LiveMapsElementsWidget.cpp | 2 + src/mvc/LiveMapsElementsWidget.h | 2 + src/mvc/ScanQueueWidget.cpp | 7 - src/mvc/ScanQueueWidget.h | 2 - src/mvc/SolverProfileWidget.cpp | 65 ++------ src/mvc/SolverProfileWidget.h | 14 +- src/mvc/SolverWidget.cpp | 14 +- src/mvc/VLM_Widget.cpp | 222 +++++--------------------- src/mvc/VLM_Widget.h | 19 +-- src/preferences/ProfileTable.cpp | 29 ++-- src/preferences/ProfileTable.h | 8 +- src/solver/LinearCoordTransformer.cpp | 8 +- 14 files changed, 86 insertions(+), 319 deletions(-) diff --git a/src/core/uProbeX.cpp b/src/core/uProbeX.cpp index 6a4f6e1..0e906de 100644 --- a/src/core/uProbeX.cpp +++ b/src/core/uProbeX.cpp @@ -442,11 +442,7 @@ void uProbeX::make_VLM_Window(VLM_Model* model) VLM_Widget* widget = new VLM_Widget(); widget->resize(1027, 768); widget->setModel(model); - /* TODO: connect properly - connect(widget, &VLM_Widget::solverStart, this, &uProbeX::solverStart); - connect(widget, &VLM_Widget::solverVariableUpdate, this, &uProbeX::solverVariableUpdate); - connect(widget, &VLM_Widget::cancelSolverVariableUpdate, this, &uProbeX::cancelSolverVariableUpdate); -*/ + SubWindow* w = new SubWindow(m_mdiArea); connect(w, &SubWindow::windowClosing, this, &uProbeX::subWindowClosed); @@ -520,11 +516,6 @@ void uProbeX::make_VLM_Window(QString path, bool newWindow) return; } - /*TODO: connect properly - connect(widget, &VLM_Widget::solverStart, this, &uProbeX::solverStart); - connect(widget, &VLM_Widget::solverVariableUpdate, this, &uProbeX::solverVariableUpdate); - connect(widget, &VLM_Widget::cancelSolverVariableUpdate, this, &uProbeX::cancelSolverVariableUpdate); - */ SubWindow* w = nullptr; if (newWindow == true) { diff --git a/src/gstar/CoordinateWidget.h b/src/gstar/CoordinateWidget.h index 797b181..16a677f 100644 --- a/src/gstar/CoordinateWidget.h +++ b/src/gstar/CoordinateWidget.h @@ -101,6 +101,8 @@ namespace gstar */ void setnullptr(); + CoordinateModel* model() { return m_model; } + private: /** diff --git a/src/mvc/LiveMapsElementsWidget.cpp b/src/mvc/LiveMapsElementsWidget.cpp index 54ee6ba..058bb7c 100644 --- a/src/mvc/LiveMapsElementsWidget.cpp +++ b/src/mvc/LiveMapsElementsWidget.cpp @@ -142,6 +142,8 @@ void LiveMapsElementsWidget::createLayout() _vlm_widget = new VLM_Widget(); _vlm_widget->setAvailScans(&_avail_scans); + gstar::CoordinateModel *coord_model = new gstar::CoordinateModel(&_linear_trans); + _vlm_widget->setCoordinateModel(coord_model); connect(_vlm_widget, &VLM_Widget::onScanUpdated, this, &LiveMapsElementsWidget::callQueueScan); _scan_queue_widget = new ScanQueueWidget(); diff --git a/src/mvc/LiveMapsElementsWidget.h b/src/mvc/LiveMapsElementsWidget.h index 2fa1ecc..b801e18 100644 --- a/src/mvc/LiveMapsElementsWidget.h +++ b/src/mvc/LiveMapsElementsWidget.h @@ -132,6 +132,8 @@ public slots: zmq::context_t *_context; + LinearCoordTransformer _linear_trans; + int _num_images; }; diff --git a/src/mvc/ScanQueueWidget.cpp b/src/mvc/ScanQueueWidget.cpp index 35126a1..2527705 100644 --- a/src/mvc/ScanQueueWidget.cpp +++ b/src/mvc/ScanQueueWidget.cpp @@ -250,13 +250,6 @@ void ScanQueueWidget::on_remove_scan() //--------------------------------------------------------------------------- -void ScanQueueWidget::onQueueKeyPress(QKeyEvent* event) -{ - -} - -//--------------------------------------------------------------------------- - void ScanQueueWidget::updateQueuedItems(std::vector &finished_plans, std::vector &queued_plans, BlueskyPlan &running_plan) { _scan_queue_table_model->setAllData(finished_plans, queued_plans, running_plan); diff --git a/src/mvc/ScanQueueWidget.h b/src/mvc/ScanQueueWidget.h index 7fc6a56..9276681 100644 --- a/src/mvc/ScanQueueWidget.h +++ b/src/mvc/ScanQueueWidget.h @@ -78,8 +78,6 @@ public slots: void on_remove_scan(); - void onQueueKeyPress(QKeyEvent*); - protected: /** diff --git a/src/mvc/SolverProfileWidget.cpp b/src/mvc/SolverProfileWidget.cpp index b5446df..72b98b8 100644 --- a/src/mvc/SolverProfileWidget.cpp +++ b/src/mvc/SolverProfileWidget.cpp @@ -64,12 +64,10 @@ void SolverProfileWidget::addProfile(QString name, QString desc, QMap attr; QMapIterator i(coef); - while (i.hasNext()) { + while (i.hasNext()) + { i.next(); - attr.push_back(Attribute(i.key(), - QString::number(i.value()), - "", - true)); + attr.push_back(Attribute(i.key(), QString::number(i.value()), "", true)); } Profile profile; @@ -82,17 +80,11 @@ void SolverProfileWidget::addProfile(QString name, QString desc, QMapaddNewItem(name, desc); - connect(m_profileTable, - SIGNAL(addItem(QString, QString)), - this, - SLOT(addProfileItem(QString, QString))); + connect(m_profileTable, &ProfileTable::addItem2, this, &SolverProfileWidget::addProfileItem); } _solverParamWidget->removeCoefficientItems(); @@ -118,22 +110,10 @@ void SolverProfileWidget::createCompontent() m_profileTable = new ProfileTable(); - connect(m_profileTable, - SIGNAL(addItem(QString, QString)), - this, - SLOT(addProfileItem(QString, QString))); - connect(m_profileTable, - SIGNAL(removeItem(int)), - this, - SLOT(removeProfileItem(int))); - connect(m_profileTable, - SIGNAL(editItem(int, QString)), - this, - SLOT(editProfileItem(int, QString))); - connect(m_profileTable, - SIGNAL(switchItem(const QItemSelection&, const QItemSelection&)), - this, - SLOT(switchProfileItem(const QItemSelection&, const QItemSelection&))); + connect(m_profileTable, &ProfileTable::addItem2, this, &SolverProfileWidget::addProfileItem); + connect(m_profileTable, &ProfileTable::removeItem, this, &SolverProfileWidget::removeProfileItem); + connect(m_profileTable, &ProfileTable::editItem, this, &SolverProfileWidget::editProfileItem); + connect(m_profileTable, &ProfileTable::switchItem, this, &SolverProfileWidget::switchProfileItem); _solverParamWidget = new SolverParameterWidget(); connect(_solverParamWidget, @@ -203,23 +183,15 @@ void SolverProfileWidget::createLayOut() */ mainLayout->addRow(_solverParamWidget); m_btnRunSolver = new QPushButton("Run Solver"); - connect(m_btnRunSolver, - SIGNAL(pressed()), - this, - SLOT(runSolver())); + connect(m_btnRunSolver, &QPushButton::pressed, this, &SolverProfileWidget::runSolver); mainLayout->addRow(m_btnRunSolver); QHBoxLayout* hLayout2 = new QHBoxLayout(); m_btnSave = new QPushButton("Save"); - connect(m_btnSave, - SIGNAL(pressed()), - this, - SLOT(accept())); + /// connect(m_btnSave, &QPushButton::pressed, this, &SolverProfileWidget::saveSolverVariableUpdate); + m_btnCancel = new QPushButton("Cancel"); - connect(m_btnCancel, - SIGNAL(pressed()), - this, - SLOT(reject())); + /// connect(m_btnCancel, &QPushButton::pressed, this, &SolverProfileWidget::cancelSolverVariableUpdate); hLayout2->addWidget(m_btnSave); hLayout2->addWidget(m_btnCancel); @@ -653,15 +625,8 @@ void SolverProfileWidget::runSolver() m_solverWidget = nullptr; m_solverWidget = new SolverWidget(this); - connect(m_solverWidget, - SIGNAL(useUpdatedVariables(const QMap)), - this, - SLOT(useUpdatedSolverVariables(const QMap ))); - - connect(m_solverWidget, - SIGNAL(cancelUpdatedVariables()), - this, - SLOT(cancelUpdatedSolverVariables())); + connect(m_solverWidget, &SolverWidget::useUpdatedVariables, this, &SolverProfileWidget::useUpdatedSolverVariables); + connect(m_solverWidget, &SolverWidget::cancelUpdatedVariables, this, &SolverProfileWidget::cancelUpdatedSolverVariables); newMinCoefs = _solver->getMinCoef(); m_solverWidget->setCoefs(minCoefs, newMinCoefs); diff --git a/src/mvc/SolverProfileWidget.h b/src/mvc/SolverProfileWidget.h index 9f85a4d..040c101 100644 --- a/src/mvc/SolverProfileWidget.h +++ b/src/mvc/SolverProfileWidget.h @@ -141,17 +141,9 @@ class SolverProfileWidget */ void solverStart(); - /** - * @brief SolverVariableUpdate - * @param valX - * @param valY - */ - void solverVariableUpdate(double valX, double valY); - - /** - * @brief CancelSolverVariableUpdate - */ - void cancelSolverVariableUpdate(); + void useUpdatedSolverVariables(const QMap); + + void cancelUpdatedSolverVariables(); private: diff --git a/src/mvc/SolverWidget.cpp b/src/mvc/SolverWidget.cpp index e914772..9223926 100644 --- a/src/mvc/SolverWidget.cpp +++ b/src/mvc/SolverWidget.cpp @@ -39,22 +39,12 @@ SolverWidget::SolverWidget(QWidget *parent) : QDialog(parent) QLabel* lblStatus = new QLabel("Status: "); m_lblStatus = new QLabel(""); - //Create Prepend plus minus buttons m_btnCancel = new QPushButton("Cancel"); m_btnUse = new QPushButton("Use New Values"); - connect(m_btnCancel, - SIGNAL(clicked()), - this, - SLOT(cancel())); - - - connect(m_btnUse, - SIGNAL(clicked()), - this, - SLOT(useNewValues())); - + connect(m_btnCancel, &QPushButton::clicked, this, &SolverWidget::cancel); + connect(m_btnUse, &QPushButton::clicked, this, &SolverWidget::useNewValues); QHBoxLayout* buttonLayout = new QHBoxLayout(); buttonLayout->setSpacing(5); diff --git a/src/mvc/VLM_Widget.cpp b/src/mvc/VLM_Widget.cpp index 96834c0..6da23f8 100644 --- a/src/mvc/VLM_Widget.cpp +++ b/src/mvc/VLM_Widget.cpp @@ -375,13 +375,15 @@ void VLM_Widget::_createSolver() _createLightToMicroCoords(id); - - if (id == ID_LINEAR) +/* +if (id == ID_LINEAR) { LinearSolver* ls = new LinearSolver(); m_solver->setImpl(ls); } - else if (id == ID_NELDER_MEAD) + else +*/ + if (id == ID_LINEAR || id == ID_NELDER_MEAD) { NelderMeadSolver* nm = new NelderMeadSolver(); @@ -1036,7 +1038,7 @@ void VLM_Widget::linkRegionToDataset() void VLM_Widget::cancelUpdatedSolverVariables() { - emit cancelSolverVariableUpdate(); + //emit cancelSolverVariableUpdate(); } @@ -1047,10 +1049,7 @@ void VLM_Widget::createCalibrationTab() m_calTreeModel = new gstar::AnnotationTreeModel(); - connect(m_calTreeModel, - SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, - SLOT(calModelDataChanged(const QModelIndex &, const QModelIndex &))); + connect(m_calTreeModel, &gstar::AnnotationTreeModel::dataChanged, this, &VLM_Widget::calModelDataChanged); m_calSelectionModel = new QItemSelectionModel(m_calTreeModel); @@ -1065,70 +1064,27 @@ void VLM_Widget::createCalibrationTab() // m_calAnnoTreeView->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents); - connect(m_calAnnoTreeView, - SIGNAL(customContextMenuRequested(const QPoint &)), - this, - SLOT(treeContextMenu(const QPoint &))); + connect(m_calAnnoTreeView, &QTreeView::customContextMenuRequested, this, &VLM_Widget::treeContextMenu); - connect(m_calAnnoTreeView, - SIGNAL(doubleClicked(const QModelIndex &)), - this, - SLOT(treeDoubleClicked(const QModelIndex &))); + connect(m_calAnnoTreeView, &QTreeView::doubleClicked, this, &VLM_Widget::treeDoubleClicked); m_btnAddCalibration = new QPushButton("Add Calibration Point"); - connect(m_btnAddCalibration, - SIGNAL(clicked()), - this, - SLOT(addCalibration())); + connect(m_btnAddCalibration, &QPushButton::clicked, this, &VLM_Widget::addCalibration); m_btnAddTopWindowPoints = new QPushButton("Add Top Window Points"); - connect(m_btnAddTopWindowPoints, - SIGNAL(clicked()), - this, - SLOT(addTopWindowPoints())); + connect(m_btnAddTopWindowPoints, &QPushButton::clicked, this, &VLM_Widget::addTopWindowPoints); m_btnAddBottomWindowPoints = new QPushButton("Add Bottom Window Points"); - connect(m_btnAddBottomWindowPoints, - SIGNAL(clicked()), - this, - SLOT(addTopWindowPoints())); + connect(m_btnAddBottomWindowPoints, &QPushButton::clicked, this, &VLM_Widget::addTopWindowPoints); m_btnRunSolver = new QPushButton("Update Transform"); - connect(m_btnRunSolver, - SIGNAL(clicked()), - this, - SLOT(openSolver())); -/* - QLabel* lblXOffset = new QLabel("2xfm:X "); - m_xOffset = new QLineEdit(); - connect(m_xOffset, - SIGNAL(editingFinished()), - this, - SLOT(offsetReturnPressed())); - connect(m_xOffset, - SIGNAL(returnPressed()), - this, - SLOT(offsetReturnPressed())); + connect(m_btnRunSolver, &QPushButton::clicked, this, &VLM_Widget::openSolver); - QLabel* lblYOffset = new QLabel("2xfm:Y "); - m_yOffset = new QLineEdit(); - connect(m_yOffset, - SIGNAL(editingFinished()), - this, - SLOT(offsetReturnPressed())); - connect(m_xOffset, - SIGNAL(returnPressed()), - this, - SLOT(offsetReturnPressed())); -*/ QVBoxLayout* infoLayout = new QVBoxLayout(); QHBoxLayout* buttonLayout = new QHBoxLayout(); QHBoxLayout* buttonLayout2 = new QHBoxLayout(); QHBoxLayout* offsetLayout = new QHBoxLayout(); -// offsetLayout->addWidget(lblXOffset); -// offsetLayout->addWidget(m_xOffset); -// offsetLayout->addWidget(lblYOffset); -// offsetLayout->addWidget(m_yOffset); + buttonLayout->addWidget(m_btnAddCalibration); buttonLayout->addWidget(m_btnRunSolver); buttonLayout2->addWidget(m_btnAddTopWindowPoints); @@ -1847,67 +1803,6 @@ void VLM_Widget::microModelDataChanged(const QModelIndex& topLeft, //--------------------------------------------------------------------------- -void VLM_Widget::offsetReturnPressed() -{ - /* - bool ok; - double valX, valY; - - QString sxOff = m_xOffset->text(); - QString syOff = m_yOffset->text(); - - QMessageBox msgBox; - msgBox.setStandardButtons(QMessageBox::Ok); - - ok = false; - valX = sxOff.toDouble(&ok); - if(ok && m_lightToMicroCoordModel != nullptr) - { - - if(false == m_lightToMicroCoordModel->setTransformerVariable( - CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_x), valX)) - { - msgBox.setText("Error setting value!"); - msgBox.exec(); - } - - } - else - { - m_xOffset->setText("0"); - } - - ok = false; - valY = syOff.toDouble(&ok); - if(ok && m_lightToMicroCoordModel != nullptr) - { - - if(false == m_lightToMicroCoordModel->setTransformerVariable( - CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_y), valY)) - { - QMessageBox msgBox; - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText("Error setting value!"); - msgBox.exec(); - } - - } - else - { - m_yOffset->setText("0"); - } - - - emit solverVariableUpdate(valX, valY); - - updateTreeView(); -*/ -} - -//--------------------------------------------------------------------------- - void VLM_Widget::setModel(VLM_Model* model) { if (_model != model) @@ -1931,10 +1826,8 @@ void VLM_Widget::preferenceChanged() { // Set the precision - m_coordinateModel->setTransformerPrecision( - Preferences::inst()->getValue(STR_PRF_DecimalPrecision).toInt()); - m_lightToMicroCoordModel->setTransformerPrecision( - Preferences::inst()->getValue(STR_PRF_DecimalPrecision).toInt()); + m_coordinateModel->setTransformerPrecision( Preferences::inst()->getValue(STR_PRF_DecimalPrecision).toInt()); + m_lightToMicroCoordModel->setTransformerPrecision( Preferences::inst()->getValue(STR_PRF_DecimalPrecision).toInt()); /* // Set the value in the calibration text linedit box if(m_lightToMicroCoordModel != nullptr) @@ -2037,12 +1930,15 @@ void VLM_Widget::restoreMarkerLoaded() } //--------------------------------------------------------------------------- - +/* void VLM_Widget::openSolver() { QList< QMap > coordPoints; SolverProfileWidget solverWidget; + connect(&solverWidget, &SolverWidget::useUpdatedVariables, this, &VLM_Widget::useUpdatedSolverVariables ); + connect(&solverWidget, &SolverWidget::cancelUpdatedVariables, this, &VLM_Widget::cancelUpdatedSolverVariables ); + if (getMarkerCoordinatePoints(coordPoints)) { solverWidget.setCoordinatePoints(&coordPoints); @@ -2053,10 +1949,11 @@ void VLM_Widget::openSolver() } } +*/ //--------------------------------------------------------------------------- -void VLM_Widget::runSolver() +void VLM_Widget::openSolver() { emit solverStart(); @@ -2069,46 +1966,18 @@ void VLM_Widget::runSolver() } m_solver->setCoordPoints(coordPoints); - QMap minCoefs; + QMap newMinCoefs; - if(m_lightToMicroCoordModel != nullptr) - { - double val; - /* - QString fmx = CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_x); - QString fmy = CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_y); - - if(m_lightToMicroCoordModel->getTransformerVariable(fmx, &val)) - { - minCoefs.insert(fmx, val); - } - else - { - QMessageBox::critical(0, "uProbeX", "Error: Could not find m2xfm_x variable in transfomer!"); - return; - } - if(m_lightToMicroCoordModel->getTransformerVariable(fmy, &val)) - { - minCoefs.insert(fmy, val); - } - else - { - QMessageBox::critical(0, "uProbeX", "Error: Could not find m2xfm_y variable in transfomer!"); - return; - } - */ - } - else + if(m_lightToMicroCoordModel == nullptr) { QMessageBox::critical(0, "uProbeX", "Error: Light to Micro Transformation Model not set!"); return; } ITransformer *trans = m_lightToMicroCoordModel->getTransformer(); + QMap minCoefs = trans->getAllCoef(); m_solver->setTransformer(trans); - m_solver->setAllCoef(trans->getAllCoef()); + m_solver->setAllCoef(minCoefs); m_solver->setMinCoef(minCoefs); QApplication::setOverrideCursor(Qt::WaitCursor); @@ -2120,9 +1989,8 @@ void VLM_Widget::runSolver() m_solverWidget = nullptr; m_solverWidget = new SolverWidget(); - //connect(m_solverWidget, &SolverWidget::useUpdatedVariables, this, SLOT(useUpdatedSolverVariables) ); - - //connect(m_solverWidget, &SolverWidget::cancelUpdatedVariables), this, SLOT(cancelUpdatedSolverVariables) ); + connect(m_solverWidget, &SolverWidget::useUpdatedVariables, this, &VLM_Widget::useUpdatedSolverVariables ); + connect(m_solverWidget, &SolverWidget::cancelUpdatedVariables, this, &VLM_Widget::cancelUpdatedSolverVariables ); newMinCoefs = m_solver->getMinCoef(); m_solverWidget->setCoefs(minCoefs, newMinCoefs); @@ -2284,10 +2152,7 @@ void VLM_Widget::setCoordinateModel(gstar::CoordinateModel *model) if (m_coordinateModel != nullptr) { - disconnect(m_coordinateModel, - SIGNAL(transformOutput(double, double, double)), - this, - SLOT(updatedPixelToLight(double, double, double))); + disconnect(m_coordinateModel, &gstar::CoordinateModel::transformOutput, this, &VLM_Widget::updatedPixelToLight); } m_coordinateModel = model; @@ -2300,10 +2165,7 @@ void VLM_Widget::setCoordinateModel(gstar::CoordinateModel *model) { m_imageViewWidget->setCoordinateModel(model); - connect(m_coordinateModel, - SIGNAL(transformOutput(double, double, double)), - this, - SLOT(updatedPixelToLight(double,double,double))); + connect(m_coordinateModel, &gstar::CoordinateModel::transformOutput, this, &VLM_Widget::updatedPixelToLight); } } @@ -2565,22 +2427,9 @@ void VLM_Widget::updatedPixelToLight(double x, double y, double z) void VLM_Widget::useUpdatedSolverVariables(const QMap vars) { - /* - if(vars.contains(CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_x)) - && vars.contains(CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_y)) ) - { - double newX = vars[CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_x)]; - double newY = vars[CoordinateTransformGlobals::keyToString( - CoordinateTransformGlobals::m2xfm_y)]; - - m_xOffset->setText(QString::number(newX)); - m_yOffset->setText(QString::number(newY)); - offsetReturnPressed(); - } - */ + + m_lightToMicroCoordModel->getTransformer()->Init(vars); + } /*--------------------------------------------------------------------------*/ @@ -2648,7 +2497,10 @@ void VLM_Widget::widgetChanged(bool enable) } /* -void solverVariableUpdate(double valX, double valY); +void VLM_Widget::solverVariableUpdate() +{ + +} void uProbeX::solverVariableUpdate(double valX, double valY) { diff --git a/src/mvc/VLM_Widget.h b/src/mvc/VLM_Widget.h index a934625..8d07ab1 100644 --- a/src/mvc/VLM_Widget.h +++ b/src/mvc/VLM_Widget.h @@ -250,11 +250,6 @@ protected slots: */ void microModelDataChanged(const QModelIndex &, const QModelIndex &); - /** - * @brief offsetReturnPressed - */ - void offsetReturnPressed(); - /** * @brief cancelUpdatedSolverVariables */ @@ -263,7 +258,7 @@ protected slots: /** * @brief runSolver */ - void runSolver(); + // void runSolver(); /** * @brief openSolver @@ -392,7 +387,7 @@ protected slots: * @param valX * @param valY */ - void solverVariableUpdate(double valX, double valY); + void solverVariableUpdate(); /** * @brief CancelSolverVariableUpdate @@ -642,16 +637,6 @@ protected slots: */ SolverWidget* m_solverWidget; - /** - * @brief m_xOffset - */ - //QLineEdit* m_xOffset; - - /** - * @brief m_xyffset - */ - //QLineEdit* m_yOffset; - /** * @brief m_pathFile */ diff --git a/src/preferences/ProfileTable.cpp b/src/preferences/ProfileTable.cpp index f5868f0..53acbbe 100644 --- a/src/preferences/ProfileTable.cpp +++ b/src/preferences/ProfileTable.cpp @@ -47,21 +47,18 @@ void ProfileTable::addNewItem(QString name, QString desc) // Check valid model if (m_solverModel == nullptr) return; - // Get row number for new item - int row = m_solverModel->rowCount(QModelIndex()) + 1; - // Add item m_solverModel->addSolverAttr(name, "0.0", desc, true); // Enable remove button if (m_solverModel->rowCount(QModelIndex()) > 0) m_btnRemove->setEnabled(true); - emit addItem(name, desc); + emit addItem2(name, desc); } //--------------------------------------------------------------------------- -void ProfileTable::addItem() +void ProfileTable::onAddItem() { addNewItem("Name", "Desc"); @@ -131,23 +128,15 @@ void ProfileTable::createComponents() m_solverTable->setSelectionModel(m_selectionModel); m_solverTable->setFixedHeight(100); - connect(m_solverModel, - SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), - this, - SLOT(editItem(const QModelIndex&, const QModelIndex&))); - - connect(m_selectionModel, - SIGNAL(selectionChanged(const QItemSelection &, - const QItemSelection &)), - this, - SIGNAL(switchItem(const QItemSelection &, - const QItemSelection &))); + connect(m_solverModel, &AttributeTableModel::dataChanged, this, &ProfileTable::onEditItem); + + connect(m_selectionModel, &QItemSelectionModel::selectionChanged, this, &ProfileTable::switchItem); // Add button m_btnAdd = new QPushButton; m_btnAdd -> setIcon(QIcon(":images/list-add.png")); m_btnAdd -> setFlat(true); m_btnAdd -> setFixedSize(32, 32); - connect(m_btnAdd, SIGNAL(clicked()), this, SLOT(addItem())); + connect(m_btnAdd, &QPushButton::clicked, this, &ProfileTable::onAddItem); // Remove button m_btnRemove = new QPushButton; @@ -157,7 +146,7 @@ void ProfileTable::createComponents() m_btnRemove->setEnabled(true); m_btnRemove -> setFixedSize(32, 32); - connect(m_btnRemove, SIGNAL(clicked()), this, SLOT(removeItem())); + connect(m_btnRemove, &QPushButton::clicked, this, &ProfileTable::onRemoveItem); // Layout for buttons QHBoxLayout* buttonLayout = new QHBoxLayout; @@ -177,7 +166,7 @@ void ProfileTable::createComponents() //--------------------------------------------------------------------------- -void ProfileTable::editItem(const QModelIndex& topLeft, const QModelIndex& bottomRight) +void ProfileTable::onEditItem(const QModelIndex& topLeft, const QModelIndex& bottomRight) { if(!topLeft.isValid()) @@ -232,7 +221,7 @@ QList ProfileTable::getSolverAttrs() //--------------------------------------------------------------------------- -void ProfileTable::removeItem() +void ProfileTable::onRemoveItem() { // Check valid model diff --git a/src/preferences/ProfileTable.h b/src/preferences/ProfileTable.h index 51984eb..030aa67 100644 --- a/src/preferences/ProfileTable.h +++ b/src/preferences/ProfileTable.h @@ -91,7 +91,7 @@ class ProfileTable * @param name * @param desc */ - void addItem(QString name, QString desc); + void addItem2(QString name, QString desc); /** * @brief deleteItem @@ -131,20 +131,20 @@ private slots: /** * @brief Internal slot to add an item. Called by the add item button. */ - void addItem(); + void onAddItem(); /** * @brief Internal slot to remove the selected item. Called by the remove * item button. */ - void removeItem(); + void onRemoveItem(); /** * @brief editItem * @param * @param */ - void editItem(const QModelIndex&, const QModelIndex&); + void onEditItem(const QModelIndex&, const QModelIndex&); private: diff --git a/src/solver/LinearCoordTransformer.cpp b/src/solver/LinearCoordTransformer.cpp index cd0e80c..9b2095c 100644 --- a/src/solver/LinearCoordTransformer.cpp +++ b/src/solver/LinearCoordTransformer.cpp @@ -40,7 +40,13 @@ QMap LinearCoordTransformer::getAllCoef() bool LinearCoordTransformer::Init(QMap globalVars) { - + for(auto &itr : _coefs.keys()) + { + if(globalVars.count(itr) > 0) + { + _coefs[itr] = globalVars.value(itr); + } + } return true; } From d7a7fdcfcb90947bab6e1357c69b380f738cc876 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Tue, 3 Dec 2024 10:33:14 -0600 Subject: [PATCH 04/11] Save and load live vlm coord transforms --- src/mvc/LiveMapsElementsWidget.cpp | 1 + src/mvc/VLM_Widget.cpp | 30 +++++++++++++++++++++++++++++- src/mvc/VLM_Widget.h | 2 +- src/preferences/Preferences.cpp | 2 ++ src/preferences/Preferences.h | 2 ++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/mvc/LiveMapsElementsWidget.cpp b/src/mvc/LiveMapsElementsWidget.cpp index 058bb7c..da63978 100644 --- a/src/mvc/LiveMapsElementsWidget.cpp +++ b/src/mvc/LiveMapsElementsWidget.cpp @@ -144,6 +144,7 @@ void LiveMapsElementsWidget::createLayout() _vlm_widget->setAvailScans(&_avail_scans); gstar::CoordinateModel *coord_model = new gstar::CoordinateModel(&_linear_trans); _vlm_widget->setCoordinateModel(coord_model); + _vlm_widget->load_live_coord_settings(); connect(_vlm_widget, &VLM_Widget::onScanUpdated, this, &LiveMapsElementsWidget::callQueueScan); _scan_queue_widget = new ScanQueueWidget(); diff --git a/src/mvc/VLM_Widget.cpp b/src/mvc/VLM_Widget.cpp index 6da23f8..2fd6d54 100644 --- a/src/mvc/VLM_Widget.cpp +++ b/src/mvc/VLM_Widget.cpp @@ -2423,13 +2423,41 @@ void VLM_Widget::updatedPixelToLight(double x, double y, double z) } -/*--------------------------------------------------------------------------*/ +//-------------------------------------------------------------------------- + +void VLM_Widget::load_live_coord_settings() +{ + QMap vars; + QStringList names = Preferences::inst()->getValue(STR_PRF_LiveCoefficientNames).toStringList(); + QStringList values = Preferences::inst()->getValue(STR_PRF_LiveCoefficientVals).toStringList(); + if(names.size() == values.size()) + { + for (int i = 0; i < names.size(); i++) + { + vars.insert(names.at(i), values.at(i).toDouble()); + } + } + m_lightToMicroCoordModel->getTransformer()->Init(vars); + +} + +//-------------------------------------------------------------------------- void VLM_Widget::useUpdatedSolverVariables(const QMap vars) { m_lightToMicroCoordModel->getTransformer()->Init(vars); + QStringList names; + QStringList values; + for (auto name : vars.keys()) + { + names.append(name); + values.append(QString::number(vars.value(name))); + } + Preferences::inst()->setValue(STR_PRF_LiveCoefficientNames, names); + Preferences::inst()->setValue(STR_PRF_LiveCoefficientVals, values); + } /*--------------------------------------------------------------------------*/ diff --git a/src/mvc/VLM_Widget.h b/src/mvc/VLM_Widget.h index 8d07ab1..2d3b4cd 100644 --- a/src/mvc/VLM_Widget.h +++ b/src/mvc/VLM_Widget.h @@ -162,7 +162,7 @@ class VLM_Widget // TODO: make sure to update all ScansRegionGraphicsItems with new pointer void setAvailScans(std::map * avail_scans) { _avail_scans = avail_scans;} - + void load_live_coord_settings(); public slots: diff --git a/src/preferences/Preferences.cpp b/src/preferences/Preferences.cpp index 3556370..0112a3c 100644 --- a/src/preferences/Preferences.cpp +++ b/src/preferences/Preferences.cpp @@ -93,6 +93,8 @@ Preferences::Preferences() {STR_PRF_SHOW_DATASET_ON_LOAD, QVariant()}, {STR_PREF_RADIO_LOAD_SELECTED_OPTION, QVariant()}, {STR_PREF_SPRECTRA_CONTROLS_HORIZONTAL_OPTION, QVariant()}, + {STR_PRF_LiveCoefficientNames, QVariant()}, + {STR_PRF_LiveCoefficientVals, QVariant()}, {STR_SAVE_QSERVER_HISTORY_LOCATION, QVariant()} }; load(); diff --git a/src/preferences/Preferences.h b/src/preferences/Preferences.h index cd71a3a..6206ed9 100644 --- a/src/preferences/Preferences.h +++ b/src/preferences/Preferences.h @@ -88,6 +88,8 @@ #define STR_PREF_RADIO_LOAD_SELECTED_OPTION "Load_Selected_Opt" #define STR_PREF_SPRECTRA_CONTROLS_HORIZONTAL_OPTION "Spectra_Controls_Horizontal" #define STR_SAVE_QSERVER_HISTORY_LOCATION "Save_Qserver_History_Location" +#define STR_PRF_LiveCoefficientNames "LiveCoefficientName" +#define STR_PRF_LiveCoefficientVals "LiveCoefficientVals" /** * @brief Read and save preferences between application restarts, the vaule key From 2d8697eff41f63beb6463d1bd5f98010e54b95d4 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Tue, 3 Dec 2024 14:59:56 -0600 Subject: [PATCH 05/11] Clean up ScanRegionGrqphicsItem. Fix corner drag drop now showing up for uproberegion --- .../Annotation/ScanRegionGraphicsItem.cpp | 897 ------------------ .../Annotation/UProbeRegionGraphicsItem.cpp | 83 +- .../Annotation/UProbeRegionGraphicsItem.h | 15 - 3 files changed, 2 insertions(+), 993 deletions(-) diff --git a/src/gstar/Annotation/ScanRegionGraphicsItem.cpp b/src/gstar/Annotation/ScanRegionGraphicsItem.cpp index 776799b..5e4fc77 100644 --- a/src/gstar/Annotation/ScanRegionGraphicsItem.cpp +++ b/src/gstar/Annotation/ScanRegionGraphicsItem.cpp @@ -23,48 +23,6 @@ ScanRegionGraphicsItem::ScanRegionGraphicsItem(std::map * connect(&_scan_dialog, &ScanRegionDialog::ScanUpdated, this, &ScanRegionGraphicsItem::onScanUpdated); prependProperty(new AnnotationProperty("Edit", QIcon(":/images/editing.png"))); -/* - m_mouseOverPixelCoordModel = nullptr; - m_lightToMicroCoordModel = nullptr; - - m_outlineColor = QColor(255, 0, 127); - m_rect = QRectF(-300, -300, 600, 600); - - // The grip size of the grip rect - setGripSize(); - m_outlineColorProp = new AnnotationProperty(UPROBE_COLOR, m_outlineColor); - - m_predictXProp = new AnnotationProperty(UPROBE_PRED_POS_X, 0.0); - m_predictYProp = new AnnotationProperty(UPROBE_PRED_POS_Y, 0.0); - - m_widthProp = new AnnotationProperty(UPROBE_WIDTH, 0.0); - m_heightProp = new AnnotationProperty(UPROBE_HEIGHT, 0.0); - - m_measuredXProp = new AnnotationProperty(UPROBE_MICRO_POS_X, "0.0"); - m_measuredYProp = new AnnotationProperty(UPROBE_MICRO_POS_Y, "0.0"); - - m_sizeProp = new AnnotationProperty(UPROBE_SIZE, 20.0); - - // m_data.push_back(m_outlineColorProp); - - m_data.push_back(m_predictXProp); - m_data.push_back(m_predictYProp); - - m_data.push_back(m_widthProp); - m_data.push_back(m_heightProp); - - setSize(m_sizeProp->getValue().toDouble()); - - connectAllProperties(); - - // Initialize rectangle size - setFlag(QGraphicsItem::ItemSendsGeometryChanges); - // Accept hover events - setAcceptHoverEvents(true); - - initialScale(); - updateStringSize(); -*/ } @@ -151,862 +109,7 @@ void ScanRegionGraphicsItem::onScanUpdated(const BlueskyPlan& plan) nplan.name = _scan_dialog.getScanName(); emit scanUpdated(nplan); -} -/* -//--------------------------------------------------------------------------- - -QString ScanRegionGraphicsItem::getUProbeName() -{ - QVariant value = this->propertyValue(UPROBE_NAME); - if (value.type() == QVariant::String) { - return value.toString(); - } - return nullptr; -} - -//--------------------------------------------------------------------------- - -QRectF ScanRegionGraphicsItem::boundingRect() const -{ - - QFontMetrics fm(m_font); - int currentStringWidth=fm.horizontalAdvance(this->propertyValue(UPROBE_NAME).toString()); - - int width; - if(currentStringWidth < m_lastStringWidth) - { - width = m_lastStringWidth; - } - else - { - width = currentStringWidth; - } - - // Make the region width 4 pixel more for gap between string and region - qreal regionWidth = width + m_rect.width()+4; - qreal regionHeight = m_rect.height(); - QSizeF regionSize = QSizeF(regionWidth, regionHeight); - - // Verify that item is in a scene - if (scene() != 0) { - QRectF scenceRect = scene()->sceneRect(); - if(mapToScene(m_rect.center()).x() < scenceRect.center().x()) - { - return QRectF(m_rect.topLeft(), - regionSize); - } - else - { - qreal textLeftPosition = m_rect.left()-1-width; - return QRectF(QPointF(textLeftPosition, m_rect.top()), - regionSize); - } - } - return QRectF(); -} - -//--------------------------------------------------------------------------- - -QRectF ScanRegionGraphicsItem::boundingRectMarker() const -{ - - return m_rect; - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::calculate() -{ - - //nothing to calculate - -} - -//--------------------------------------------------------------------------- - -const QString ScanRegionGraphicsItem::displayName() const -{ - - const QString name = QString("Micro Probe Region"); - return name; - -} - -//--------------------------------------------------------------------------- - -AbstractGraphicsItem* ScanRegionGraphicsItem::duplicate() -{ - - ScanRegionGraphicsItem* item = new ScanRegionGraphicsItem(); - - QColor color(m_outlineColorProp->getValue().toString()); - item->setColor(color); - item->setPos(pos()); - item->setSameRect(m_rect); - - item->setMouseOverPixelCoordModel(m_mouseOverPixelCoordModel); - item->setLightToMicroCoordModel(m_lightToMicroCoordModel); - return item; - -} - -//--------------------------------------------------------------------------- - -double ScanRegionGraphicsItem::getFactorX() -{ - - //TODO: add annotation property - return 1.0; - -} - -//--------------------------------------------------------------------------- - -double ScanRegionGraphicsItem::getFactorY() -{ - - //TODO: add annotation property - return 1.0; - -} - -//--------------------------------------------------------------------------- - -double ScanRegionGraphicsItem::getHeight() -{ - - return m_heightProp->getValue().toDouble(); - -} - -//--------------------------------------------------------------------------- - -double ScanRegionGraphicsItem::getWidth() -{ - - return m_widthProp->getValue().toDouble(); - -} - -//--------------------------------------------------------------------------- - -double ScanRegionGraphicsItem::getX() -{ - - return m_predictXProp->getValue().toDouble(); - -} - -//--------------------------------------------------------------------------- - -double ScanRegionGraphicsItem::getY() -{ - - return m_predictYProp->getValue().toDouble(); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event) -{ - - // Mark unused - Q_UNUSED(event); - - // Return if item is not selected - if (!isSelected()) { - return; - } - - // Set cursor - setCursor(Qt::SizeAllCursor); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) -{ - - // Mark unused - Q_UNUSED(event); - - // Reset cursor - unsetCursor(); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event) -{ - - // Return if item is not selected - if (!isSelected()) { - return; - } - - // Mouse click position (in item coordinates) - QPointF pt = event -> pos(); - - // Check for bottom right grip - if (pt.x() <= m_rect.right() && - pt.y() <= m_rect.bottom() && - pt.x() >= m_rect.right() - m_gripSize && - pt.y() >= m_rect.bottom() - m_gripSize) - { - setCursor(Qt::SizeFDiagCursor); - }// bottom left - else if (pt.x() >= m_rect.left() && - pt.y() >= m_rect.bottom() - m_gripSize && - pt.x() <= m_rect.left() + m_gripSize && - pt.y() <= m_rect.bottom()) - { - setCursor(Qt::SizeBDiagCursor); - }//top left - else if (pt.x() <= m_rect.left() + m_gripSize && - pt.y() <= m_rect.top() + m_gripSize && - pt.x() >= m_rect.left() && - pt.y() >= m_rect.top()) - { - setCursor(Qt::SizeFDiagCursor); - }//top right - else if (pt.x() >= m_rect.right() - m_gripSize && - pt.y() >= m_rect.top()&& - pt.x() <= m_rect.right() && - pt.y() <= m_rect.top() + m_gripSize ) - { - setCursor(Qt::SizeBDiagCursor); - } - // Reset cursor - else { - setCursor(Qt::OpenHandCursor); - } - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::initialScale() -{ - - QTransform trans = getFirstViewTransform(); - if (trans.isScaling()) - { - bool isInvertable = false; - QTransform invTrans = trans.inverted(&isInvertable); - if (isInvertable) - { - double xScale = invTrans.m11(); - double s = scale(); - if (s != xScale) - { - setScale(100*xScale); - } - } - } - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - - // Current mouse position - QPointF pt = event -> pos(); - - // Last mouse position - QPointF lpt = event -> lastPos(); - - // Get boundary item rectangle - QRectF boundRect = ((ImageViewScene*) scene()) -> pixRect(); - - // User interacted with a resize grip - if (m_grip != None) { - prepareGeometryChange(); - double last_y = m_rect.y(); - double last_x = m_rect.x(); - - // Perform resize based on the edge the user is moving & limit within parent. - - // Update Height - if (m_grip == TopLeft || m_grip == TopRight) { - if (mapToScene(pt).y() <= boundRect.top()) { - m_rect.setTop(mapFromScene(boundRect.topLeft()).y()); - } else { - m_rect.setY(pt.y()); - } - } - if (m_grip == BottomLeft || m_grip == BottomRight) { - if (mapToScene(pt).y() >= boundRect.bottom()) { - m_rect.setBottom(mapFromScene(boundRect.bottomLeft()).y()); - } else { - m_rect.setHeight(pt.y() - m_rect.top()); - } - } - - // Update Width - if (m_grip == BottomLeft || m_grip == TopLeft) { - if (mapToScene(pt).x() <= boundRect.left()) { - m_rect.setLeft(mapFromScene(boundRect.topLeft()).x()); - } else { - m_rect.setX(pt.x()); - } - } - if (m_grip == BottomRight || m_grip == TopRight) { - if (mapToScene(pt).x() >= boundRect.right()) { - m_rect.setRight(mapFromScene(boundRect.topRight()).x()); - } else { - m_rect.setWidth(pt.x() - m_rect.left()); - } - } - - // Enforce a minimum size - if (m_rect.width() < 5) { - m_rect.setX(last_x); - m_rect.setWidth(5); - } - if (m_rect.height() < 5) { - m_rect.setY(last_y); - m_rect.setHeight(5); - } - } - // No grip selected (this is a move) - else { - // Queue an update - update(); - - // Pass mouse position - QGraphicsItem::mouseMoveEvent(event); - setPos(pos().x(), pos().y()); - - // Check bounds - // setPos(qBound(boundRect.left(), pos().x(), - // boundRect.right() - m_rect.width()), - // qBound(boundRect.top(), pos().y(), - // boundRect.bottom() - m_rect.height())); - // Emit change - //emit itemChanged(this); - - } - - setGripSize(); -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::zoomToRegion() -{ - // Estimated minimum text size. Should be predicted. - QGraphicsView* v = scene()->views().first(); - QSize size = v->size(); - - double rectWidth = m_rect.width(); - double rectHeight = m_rect.height(); - - qreal predictedScale = 0; - if (rectHeight == rectWidth || rectHeight < rectWidth) { - predictedScale = rectWidth / size.width(); - - } else if (rectWidth < rectHeight) { - predictedScale = rectHeight / size.height(); - } - - int predictedPixelSize = predictFontPixelSizeByScale(predictedScale); - // Apply predicted pixel size to factor in when zoom to region is performed. - m_font.setPixelSize(predictedPixelSize); - m_lastStringWidth = 0; - - ImageViewScene* imageViewScene = ((ImageViewScene*) scene()); - imageViewScene->updateZoom(this); -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - - // Mouse click position (in item coordinates) - QPointF pt = event -> pos(); - - // Check for bottom right grip - if (pt.x() <= m_rect.right() && - pt.y() <= m_rect.bottom() && - pt.x() >= m_rect.right() - m_gripSize && - pt.y() >= m_rect.bottom() - m_gripSize) - { - m_grip = BottomRight; - }// bottom left - else if (pt.x() >= m_rect.left() && - pt.y() >= m_rect.bottom() - m_gripSize && - pt.x() <= m_rect.left() + m_gripSize && - pt.y() <= m_rect.bottom()) - { - m_grip = BottomLeft; - }//top left - else if (pt.x() <= m_rect.left() + m_gripSize && - pt.y() <= m_rect.top() + m_gripSize && - pt.x() >= m_rect.left() && - pt.y() >= m_rect.top()) - { - m_grip = TopLeft; - }//top right - else if (pt.x() >= m_rect.right() - m_gripSize && - pt.y() >= m_rect.top()&& - pt.x() <= m_rect.right() && - pt.y() <= m_rect.top() + m_gripSize ) - { - m_grip = TopRight; - } - // Reset cursor - else - { - m_grip = None; - } - - // Queue an update - update(); - - // Pass mouse event - QGraphicsItem::mousePressEvent(event); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - - // No grip selected - m_grip = None; - - // Queue an update - update(); - - // Pass mouse event - QGraphicsItem::mouseReleaseEvent(event); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::paint(QPainter* painter, - const QStyleOptionGraphicsItem* option, - QWidget* widget) -{ - - Q_UNUSED(widget); - // Draw the center of the rect. - - // Draw grip box - QRectF gripBottomLeft(m_rect.left(), - m_rect.bottom() - m_gripSize, - m_gripSize, m_gripSize); - - QRectF gripBottomRight(m_rect.right() - m_gripSize, - m_rect.bottom() - m_gripSize, - m_gripSize, m_gripSize); - - QRectF gripTopLeft(m_rect.left(), - m_rect.top(), - m_gripSize, m_gripSize); - - QRectF gripTopRight(m_rect.right() - m_gripSize, - m_rect.top(), - m_gripSize, m_gripSize); - - - QPen pen(m_outlineColor); - if (option->state & QStyle::State_Selected) - { - pen.setStyle(Qt::DotLine); - pen.setWidth(2); - - } - pen.setCosmetic(true); - - painter->setPen(pen); - painter->drawRect(m_rect); - - if(QApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) - { - - if(m_rect.width()<10&&m_rect.height()<10) - { - painter->drawPoint(m_rect.center()); - } - else - { - // Draw the crosshair in the center of the region box. - double midX = m_rect.left() + ( ( m_rect.right() - m_rect.left() ) * 0.5); - double midY = m_rect.bottom() + ( ( m_rect.top() - m_rect.bottom() ) * 0.5); - double thirdX = ( m_rect.right() - m_rect.left() ) * 0.1; - double thirdY = ( m_rect.top() - m_rect.bottom() ) * 0.1; - double cX = m_rect.center().x(); - double cY = m_rect.center().y(); - painter->drawLine(midX, cY - thirdY, midX, cY + thirdY); - painter->drawLine(cX - thirdX, midY, cX + thirdX, midY); - } - - painter->drawRect(gripBottomLeft); - painter->drawRect(gripBottomRight); - painter->drawRect(gripTopLeft); - painter->drawRect(gripTopRight); - } - updateStringSize(); - painter->setFont(m_font); - - QString str = this->propertyValue(UPROBE_NAME).toString(); - - // Make 1 pixel wider for gap between string and region box - if (scene() != 0) - { - QRectF scenceRect = scene()->sceneRect(); - - if( mapToScene(m_rect.center()).x() < scenceRect.center().x()) - { - double txtRightPosition = m_rect.right()+1; - painter->drawText( QPointF(txtRightPosition, m_rect.center().y() ), str); - } - else - { - double textLeftPosition = m_rect.left()-1-m_lastStringWidth; - painter->drawText( QPointF(textLeftPosition, m_rect.center().y() ), str); - } - } - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setColor(const QColor& color) -{ - - // Set color - m_outlineColor = color; - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setGripSize() -{ - - if (m_rect.width() < m_rect.height()) - { - m_gripSize = 0.1 * m_rect.width(); - } - else - { - m_gripSize = 0.1 * m_rect.height(); - } - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setHeight(double height) -{ - - // Prepare for change - prepareGeometryChange(); - - // Set width - m_rect.setHeight(height); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setMouseOverPixelCoordModel(CoordinateModel* model) -{ - - if(m_mouseOverPixelCoordModel != nullptr) - { - disconnect(m_mouseOverPixelCoordModel, - SIGNAL(modelUpdated()), - this, - SLOT(updateModel())); - } - - m_mouseOverPixelCoordModel = model; - - if(m_mouseOverPixelCoordModel != nullptr) - { - connect(m_mouseOverPixelCoordModel, - SIGNAL(modelUpdated()), - this, - SLOT(updateModel())); - } - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setLightToMicroCoordModel(CoordinateModel* model) -{ - - if(m_lightToMicroCoordModel != nullptr) - { - disconnect(m_lightToMicroCoordModel, - SIGNAL(modelUpdated()), - this, - SLOT(updateModel())); - } - - m_lightToMicroCoordModel = model; - - if(m_lightToMicroCoordModel != nullptr) - { - connect(m_lightToMicroCoordModel, - SIGNAL(modelUpdated()), - this, - SLOT(updateModel())); - } - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setSameRect(QRectF& rect) -{ - - // Prepare for change - prepareGeometryChange(); - - // Set y - m_rect = rect; - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setSize(double size) -{ - - m_size = size; - - update(); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setWidth(double width) -{ - - // Prepare for change - prepareGeometryChange(); - - // Set width - m_rect.setWidth(width); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setX(double x) -{ - - // Prepare for change - prepareGeometryChange(); - - // Set x - setPos(x, pos().y()); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::setY(double y) -{ - - // Prepare for change - prepareGeometryChange(); - - // Set y - setPos(pos().x(), y); - -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::updateModel() -{ - // Center needs to be calculated uProbe position - QPointF position = mapToScene(m_rect.center()); - - QPointF topLeft = mapToScene(m_rect.topLeft()); - QPointF topRight = mapToScene(m_rect.topRight()); - QPointF bottomRight = mapToScene(m_rect.bottomRight()); - - if(m_mouseOverPixelCoordModel != nullptr) - { - double x,y,z; - m_mouseOverPixelCoordModel->runTransformer((double)position.x(), - (double)position.y(), - 0.0, - &x, - &y, - &z); - - double topLeftX, topLeftY, topLeftZ; - double topRightX, topRightY, topRightZ; - double bottomRightX, bottomRightY, bottomRightZ; - m_mouseOverPixelCoordModel->runTransformer((double)topLeft.x(), - (double)topLeft.y(), - 0.0, - &topLeftX, - &topLeftY, - &topLeftZ); - m_mouseOverPixelCoordModel->runTransformer((double)topRight.x(), - (double)topRight.y(), - 0.0, - &topRightX, - &topRightY, - &topRightZ); - m_mouseOverPixelCoordModel->runTransformer((double)bottomRight.x(), - (double)bottomRight.y(), - 0.0, - &bottomRightX, - &bottomRightY, - &bottomRightZ); - - if(m_lightToMicroCoordModel != nullptr) - { - double x1,y1,z1; - m_lightToMicroCoordModel->runTransformer(x, - y, - 0.0, - &x1, - &y1, - &z1); - m_predictXProp->setValue(x1); - m_predictYProp->setValue(y1); - - double topLeftX1, topLeftY1, topLeftZ1; - double topRightX1, topRightY1, topRightZ1; - double bottomRightX1, bottomRightY1, bottomRightZ1; - m_lightToMicroCoordModel->runTransformer(topLeftX, - topLeftY, - 0.0, - &topLeftX1, - &topLeftY1, - &topLeftZ1); - m_lightToMicroCoordModel->runTransformer(topRightX, - topRightY, - 0.0, - &topRightX1, - &topRightY1, - &topRightZ1); - m_lightToMicroCoordModel->runTransformer(bottomRightX, - bottomRightY, - 0.0, - &bottomRightX1, - &bottomRightY1, - &bottomRightZ1); - - m_widthProp->setValue(topLeftX1-topRightX1); - m_heightProp->setValue(topRightY1-bottomRightY1); - - } - - } - else - { - m_predictXProp->setValue(0.0); - m_predictYProp->setValue(0.0); - m_widthProp->setValue(topRight.x()-topLeft.x()); - m_heightProp->setValue(bottomRight.y()-topRight.y()); - } -} - -//--------------------------------------------------------------------------- - -void ScanRegionGraphicsItem::updateStringSize() -{ - - double pixelSize; - - QTransform trans = getFirstViewTransform(); - if (trans.isScaling()) - { - bool isInvertable = false; - QTransform invTrans = trans.inverted(&isInvertable); - if (isInvertable) - { - qreal horizontalScalingFactor = invTrans.m11(); - - pixelSize = predictFontPixelSizeByScale(horizontalScalingFactor); - } - } - else - { - pixelSize = 10; - } - - -// if(m_rect.width() > 11) -// { -// pixelSize = m_rect.width()/10; -// } -// else -// { -// pixelSize = 1; -// } - - - m_font.setPixelSize(pixelSize); - - QString str = this->propertyValue(UPROBE_NAME).toString(); - - QFontMetrics fm(m_font); - int currentStringWidth=fm.horizontalAdvance(str); - m_lastStringWidth = currentStringWidth; - -} - -int ScanRegionGraphicsItem::predictFontPixelSizeByScale(qreal scale) { - double pixelSizeScalingFactor; - - if (scale < 0.20) { - pixelSizeScalingFactor = 21.0; - } - else if (scale < 0.35) { - pixelSizeScalingFactor = 18.0; - } - else if (scale < 0.50) { - pixelSizeScalingFactor = 15.0; - } - else if (scale < 0.65) { - pixelSizeScalingFactor = 13.0; - }else { - pixelSizeScalingFactor = 12.0; - } - - - int pixelSize = scale * pixelSizeScalingFactor; - return std::max((double)pixelSize, 3.0); - } //--------------------------------------------------------------------------- -void ScanRegionGraphicsItem::updateView() -{ - //double x = m_positionXProp->getValue().toDouble(); - //double y = m_positionYProp->getValue().toDouble(); - - setSize(m_sizeProp->getValue().toDouble()); - //setX(x); - //setY(y); - - m_outlineColor = QColor(m_outlineColorProp->getValue().toString()); - -} -*/ -//--------------------------------------------------------------------------- - diff --git a/src/gstar/Annotation/UProbeRegionGraphicsItem.cpp b/src/gstar/Annotation/UProbeRegionGraphicsItem.cpp index befc890..73c613a 100644 --- a/src/gstar/Annotation/UProbeRegionGraphicsItem.cpp +++ b/src/gstar/Annotation/UProbeRegionGraphicsItem.cpp @@ -274,86 +274,6 @@ double UProbeRegionGraphicsItem::getY() //--------------------------------------------------------------------------- -void UProbeRegionGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event) -{ - - // Mark unused - Q_UNUSED(event); - - // Return if item is not selected - if (!isSelected()) { - return; - } - - // Set cursor - setCursor(Qt::SizeAllCursor); - -} - -//--------------------------------------------------------------------------- - -void UProbeRegionGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) -{ - - // Mark unused - Q_UNUSED(event); - - // Reset cursor - unsetCursor(); - -} - -//--------------------------------------------------------------------------- - -void UProbeRegionGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event) -{ - - // Return if item is not selected - if (!isSelected()) { - return; - } - - // Mouse click position (in item coordinates) - QPointF pt = event -> pos(); - - // Check for bottom right grip - if (pt.x() <= m_rect.right() && - pt.y() <= m_rect.bottom() && - pt.x() >= m_rect.right() - m_gripSize && - pt.y() >= m_rect.bottom() - m_gripSize) - { - setCursor(Qt::SizeFDiagCursor); - }// bottom left - else if (pt.x() >= m_rect.left() && - pt.y() >= m_rect.bottom() - m_gripSize && - pt.x() <= m_rect.left() + m_gripSize && - pt.y() <= m_rect.bottom()) - { - setCursor(Qt::SizeBDiagCursor); - }//top left - else if (pt.x() <= m_rect.left() + m_gripSize && - pt.y() <= m_rect.top() + m_gripSize && - pt.x() >= m_rect.left() && - pt.y() >= m_rect.top()) - { - setCursor(Qt::SizeFDiagCursor); - }//top right - else if (pt.x() >= m_rect.right() - m_gripSize && - pt.y() >= m_rect.top()&& - pt.x() <= m_rect.right() && - pt.y() <= m_rect.top() + m_gripSize ) - { - setCursor(Qt::SizeBDiagCursor); - } - // Reset cursor - else { - setCursor(Qt::OpenHandCursor); - } - -} - -//--------------------------------------------------------------------------- - void UProbeRegionGraphicsItem::initialScale() { @@ -596,7 +516,8 @@ void UProbeRegionGraphicsItem::paint(QPainter* painter, painter->setPen(pen); painter->drawRect(m_rect); - if(QApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) + //if(QApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) + if(isSelected()) { if(m_rect.width()<10&&m_rect.height()<10) diff --git a/src/gstar/Annotation/UProbeRegionGraphicsItem.h b/src/gstar/Annotation/UProbeRegionGraphicsItem.h index 6e67d8c..5ecbe03 100644 --- a/src/gstar/Annotation/UProbeRegionGraphicsItem.h +++ b/src/gstar/Annotation/UProbeRegionGraphicsItem.h @@ -252,21 +252,6 @@ class UProbeRegionGraphicsItem : public AbstractGraphicsItem TopRight }; - /** - * Reimplemented from QGraphicsItem. See Qt documentation. - */ - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - - /** - * Reimplemented from QGraphicsItem. See Qt documentation. - */ - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - - /** - * Reimplemented from QGraphicsItem. See Qt documentation. - */ - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - /** * Reimplemented from QGraphicsItem. See Qt documentation. */ From 1a99357915688bbe8f784ba3adad266935dd010c Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Fri, 6 Dec 2024 09:09:55 -0600 Subject: [PATCH 06/11] Fix batch gen range func --- src/mvc/ScanRegionDialog.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/mvc/ScanRegionDialog.cpp b/src/mvc/ScanRegionDialog.cpp index 079077e..c72e9d9 100644 --- a/src/mvc/ScanRegionDialog.cpp +++ b/src/mvc/ScanRegionDialog.cpp @@ -45,10 +45,14 @@ void ScanRegionDialog::_createLayout() _chk_batch_scan = new QCheckBox("Set Batch Scan"); connect(_chk_batch_scan, &QCheckBox::checkStateChanged, this, &ScanRegionDialog::onBatchScanChanged); + QLabel* startLabel = new QLabel("Start Value"); + QLabel* endLabel = new QLabel("End Value"); + QLabel* numItrLabel = new QLabel("Number Iter"); + _cb_batch_prop = new QComboBox(); - _batch_start = new QLineEdit("Start Value"); - _batch_end = new QLineEdit("End Value"); - _batch_num = new QLineEdit("Number Iter"); + _batch_start = new QLineEdit("1"); + _batch_end = new QLineEdit("10"); + _batch_num = new QLineEdit("10"); _cb_batch_prop->setEnabled(false); _batch_start->setEnabled(false); @@ -70,12 +74,16 @@ void ScanRegionDialog::_createLayout() type_layout->addWidget(new QLabel("Scan Type: ")); type_layout->addWidget(_scan_type); - QHBoxLayout* batch_layout = new QHBoxLayout(); - batch_layout->addWidget(_chk_batch_scan); - batch_layout->addWidget(_cb_batch_prop); - batch_layout->addWidget(_batch_start); - batch_layout->addWidget(_batch_end); - batch_layout->addWidget(_batch_num); + QGridLayout* batch_layout = new QGridLayout(); + batch_layout->addWidget(_chk_batch_scan, 0, 0); + batch_layout->addWidget(startLabel, 0, 1); + batch_layout->addWidget(endLabel, 0 , 2); + batch_layout->addWidget(numItrLabel, 0, 3); + + batch_layout->addWidget(_cb_batch_prop, 1, 0); + batch_layout->addWidget(_batch_start, 1, 1); + batch_layout->addWidget(_batch_end, 1, 2); + batch_layout->addWidget(_batch_num, 1, 3); QHBoxLayout* button_layout = new QHBoxLayout(); @@ -129,7 +137,7 @@ void ScanRegionDialog::onUpdateAndQueue() float start = _batch_start->text().toFloat(); float end = _batch_end->text().toFloat(); int num = _batch_num->text().toInt(); - float inc = ( (end - start) + 1 )/ (float)num; + float inc = ( end - start )/ (float)(num - 1); for(int i=0; i Date: Tue, 10 Dec 2024 10:54:00 -0600 Subject: [PATCH 07/11] Do not convert bluesky params , just pass them as is --- src/mvc/BlueskyComm.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mvc/BlueskyComm.h b/src/mvc/BlueskyComm.h index bdec583..1657549 100644 --- a/src/mvc/BlueskyComm.h +++ b/src/mvc/BlueskyComm.h @@ -123,17 +123,20 @@ class BlueskyComm } args.append(inner_args); } - else if(itr.second.kind == BlueskyParamType::String && itr.second.default_val.length() > 0) + //else if(itr.second.kind == BlueskyParamType::String && itr.second.default_val.length() > 0) { kwargs[itr.first] = itr.second.default_val; } + /* else if(itr.second.kind == BlueskyParamType::Numeral && itr.second.default_val.length() > 0) { kwargs[itr.first] = QJsonValue::fromVariant(itr.second.default_val.toDouble()); } + */ } item["kwargs"] = kwargs; item["args"] = args; + //qDebug()< Date: Tue, 17 Dec 2024 11:19:30 -0600 Subject: [PATCH 08/11] Fixed issue where we converted string to numeric for bluesky plans. Added bool delegate for True,False parameters for BlueSky --- src/mvc/BlueskyComm.h | 54 ++++++++++++++++++------------ src/mvc/BlueskyPlan.h | 2 +- src/mvc/LiveMapsElementsWidget.cpp | 4 +-- src/mvc/ScanQueueTableModel.h | 54 ++++++++++++++++++------------ src/mvc/ScanQueueWidget.cpp | 9 +++++ src/mvc/ScanQueueWidget.h | 2 +- src/mvc/ScanRegionDialog.cpp | 32 +++++++++++++++--- src/mvc/ScanRegionDialog.h | 3 ++ src/mvc/ScanTableModel.h | 39 +++++++++++++++------ 9 files changed, 135 insertions(+), 64 deletions(-) diff --git a/src/mvc/BlueskyComm.h b/src/mvc/BlueskyComm.h index 1657549..5d0e28e 100644 --- a/src/mvc/BlueskyComm.h +++ b/src/mvc/BlueskyComm.h @@ -113,10 +113,10 @@ class BlueskyComm for(auto itr: plan.parameters) { //logI< 0) { - kwargs[itr.first] = itr.second.default_val; + kwargs[itr.name] = itr.default_val; } /* else if(itr.second.kind == BlueskyParamType::Numeral && itr.second.default_val.length() > 0) @@ -487,20 +487,21 @@ class BlueskyComm QJsonArray params_obj = pobj["parameters"].toArray(); for( auto itr2 : params_obj) { + BlueskyParam bsparam; QJsonObject param = itr2.toObject(); if(param.contains("name")) { - plans[pobj["name"].toString()].parameters[param["name"].toString()].name = param["name"].toString(); + bsparam.name = param["name"].toString(); if(param.contains("default")) { if(param["default"].toString() != "None") { - plans[pobj["name"].toString()].parameters[param["name"].toString()].default_val = param["default"].toString(); + bsparam.default_val = param["default"].toString(); } } if(param.contains("description")) { - plans[pobj["name"].toString()].parameters[param["name"].toString()].description = param["description"].toString(); + bsparam.description = param["description"].toString(); } } if(param.contains("kind")) @@ -512,16 +513,17 @@ class BlueskyComm switch (tval) { case 1: - plans[pobj["name"].toString()].parameters[param["name"].toString()].kind = BlueskyParamType::Numeral; - break; + bsparam.kind = BlueskyParamType::Numeral; + break; case 3: - plans[pobj["name"].toString()].parameters[param["name"].toString()].kind = BlueskyParamType::String; - break; + bsparam.kind = BlueskyParamType::String; + break; default: - break; + break; } } } + plans[pobj["name"].toString()].parameters.push_back(bsparam); } } } @@ -608,7 +610,7 @@ class BlueskyComm { bsp.default_val = kwargs.value(pitr).toString(); } - plan.parameters[pitr] = bsp; + plan.parameters.push_back(bsp); } } if(param.contains("kwargs")) @@ -618,7 +620,7 @@ class BlueskyComm { BlueskyParam bsp; bsp.name = pitr; - + /* if(kwargs.value(pitr).isDouble()) { double p = kwargs.value(pitr).toDouble(); @@ -630,7 +632,9 @@ class BlueskyComm bsp.default_val = kwargs.value(pitr).toString(); bsp.kind = BlueskyParamType::String; } - plan.parameters[pitr] = bsp; + */ + bsp.default_val = kwargs.value(pitr).toString(); + plan.parameters.push_back(bsp); } } if(param.contains("user")) @@ -687,7 +691,7 @@ class BlueskyComm { BlueskyParam bsp; bsp.name = pitr; - + /* if(kwargs.value(pitr).isDouble()) { double p = kwargs.value(pitr).toDouble(); @@ -696,10 +700,12 @@ class BlueskyComm } else if( kwargs.value(pitr).isString() ) { - bsp.default_val = kwargs.value(pitr).toString(); + c bsp.kind = BlueskyParamType::String; } - running_plan.parameters[pitr] = bsp; + */ + bsp.default_val = kwargs.value(pitr).toString(); + running_plan.parameters.push_back(bsp); } } if(running_item.contains("kwargs")) @@ -709,7 +715,7 @@ class BlueskyComm { BlueskyParam bsp; bsp.name = pitr; - + /* if(kwargs.value(pitr).isDouble()) { double p = kwargs.value(pitr).toDouble(); @@ -721,7 +727,9 @@ class BlueskyComm bsp.default_val = kwargs.value(pitr).toString(); bsp.kind = BlueskyParamType::String; } - running_plan.parameters[pitr] = bsp; + */ + bsp.default_val = kwargs.value(pitr).toString(); + running_plan.parameters.push_back(bsp); } } if(running_item.contains("user")) @@ -854,7 +862,7 @@ class BlueskyComm { bsp.default_val = kwargs.value(pitr).toString(); } - plan.parameters[pitr] = bsp; + plan.parameters.push_back(bsp); } } if(param.contains("kwargs")) @@ -864,7 +872,7 @@ class BlueskyComm { BlueskyParam bsp; bsp.name = pitr; - + /* if(kwargs.value(pitr).isDouble()) { double p = kwargs.value(pitr).toDouble(); @@ -876,7 +884,9 @@ class BlueskyComm bsp.default_val = kwargs.value(pitr).toString(); bsp.kind = BlueskyParamType::String; } - plan.parameters[pitr] = bsp; + */ + bsp.default_val = kwargs.value(pitr).toString(); + plan.parameters.push_back(bsp); } } if(param.contains("result")) diff --git a/src/mvc/BlueskyPlan.h b/src/mvc/BlueskyPlan.h index 909c935..c23498d 100644 --- a/src/mvc/BlueskyPlan.h +++ b/src/mvc/BlueskyPlan.h @@ -58,7 +58,7 @@ struct BlueskyPlan QString type; QString description; QString module; - std::unordered_map parameters; + std::vector parameters; BlueskyResult result; QString uuid; QString user; diff --git a/src/mvc/LiveMapsElementsWidget.cpp b/src/mvc/LiveMapsElementsWidget.cpp index da63978..a0d0886 100644 --- a/src/mvc/LiveMapsElementsWidget.cpp +++ b/src/mvc/LiveMapsElementsWidget.cpp @@ -411,7 +411,7 @@ void LiveMapsElementsWidget::saveHistory() out << "Name,Type,"; for(auto & itr: _finished_scans.at(0).parameters) { - out< 0) @@ -156,17 +160,10 @@ class ScanQueueTableModel : public QAbstractTableModel { return rowData.result.msg; } - - int idx = 0; - for( auto itr: rowData.parameters) + else { - if(idx == section -1 ) - { - return itr.second.default_val; - } - idx++; + return rowData.parameters.at(section-1).default_val; } - } else if (role == Qt::BackgroundRole) { @@ -179,9 +176,18 @@ class ScanQueueTableModel : public QAbstractTableModel return QColor(Qt::darkGreen); } } + else if (role == Qt::EditRole) + { + if(section > 0 && section <= parms_size) + { + return rowData.parameters.at(section-1).default_val; + } + } return QVariant(); } + //--------------------------------------------------------------------------- + QVariant headerData(int section, Qt::Orientation orientation, int role) const override { // Check this is DisplayRole @@ -194,7 +200,7 @@ class ScanQueueTableModel : public QAbstractTableModel { return _headers[section]; } - else + else if (section > 0) { if(_data.size() > 0) { @@ -217,14 +223,9 @@ class ScanQueueTableModel : public QAbstractTableModel { return "msg"; } - int idx = 0; - for( auto itr: rowData.parameters) + else if (parms_size > (section -1) ) { - if(idx == section -1 ) - { - return itr.second.name; - } - idx++; + return rowData.parameters.at(section-1).name; } } return QVariant(" "); @@ -261,6 +262,13 @@ class ScanQueueTableModel : public QAbstractTableModel //--------------------------------------------------------------------------- + void setAvailScans(std::map * avail_scans) + { + _avail_scans = avail_scans; + } + + //--------------------------------------------------------------------------- + void setAllData(std::vector &finished_plans, std::vector &queued_plans, BlueskyPlan &running_plan) { _last_finished_idx = finished_plans.size(); @@ -268,15 +276,15 @@ class ScanQueueTableModel : public QAbstractTableModel _data.clear(); for(auto itr : finished_plans) { - _data.append(itr); + _data.push_back(itr); } if(running_plan.type.length() > 0) { - _data.append(running_plan); + _data.push_back(running_plan); } for(auto itr : queued_plans) { - _data.append(itr); + _data.push_back(itr); } endResetModel(); } @@ -295,7 +303,7 @@ class ScanQueueTableModel : public QAbstractTableModel if(idx == index.column() && value.toString().length() >0) { // this will be refreshed from qserver - itr.second.default_val = value.toString(); + itr.default_val = value.toString(); emit planChanged(_data.at(index.row())); return false; // return false to make sure we get this value from qserver } @@ -318,7 +326,9 @@ class ScanQueueTableModel : public QAbstractTableModel private: int _last_finished_idx; - QList _data; + std::vector _data; + + std::map *_avail_scans; QString _headers[4]; }; diff --git a/src/mvc/ScanQueueWidget.cpp b/src/mvc/ScanQueueWidget.cpp index 2527705..e54a2c9 100644 --- a/src/mvc/ScanQueueWidget.cpp +++ b/src/mvc/ScanQueueWidget.cpp @@ -266,6 +266,15 @@ void ScanQueueWidget::updateQueuedItems(std::vector &finished_plans //--------------------------------------------------------------------------- +void ScanQueueWidget::setAvailScans(std::map * avail_scans) +{ + _avail_scans = avail_scans; + _scan_dialog.setAvailScans(avail_scans); + _scan_queue_table_model->setAvailScans(avail_scans); +} + +//--------------------------------------------------------------------------- + void ScanQueueWidget::newDataArrived(const QString& data) { //_te_qs_console->insertPlainText(data); diff --git a/src/mvc/ScanQueueWidget.h b/src/mvc/ScanQueueWidget.h index 9276681..315617a 100644 --- a/src/mvc/ScanQueueWidget.h +++ b/src/mvc/ScanQueueWidget.h @@ -38,7 +38,7 @@ class ScanQueueWidget : public QWidget void updateQueuedItems( std::vector &finished_plans, std::vector &queued_plans, BlueskyPlan &running_plan); - void setAvailScans(std::map * avail_scans) { _avail_scans = avail_scans; _scan_dialog.setAvailScans(avail_scans);} + void setAvailScans(std::map * avail_scans); signals: void queueNeedsToBeUpdated(); diff --git a/src/mvc/ScanRegionDialog.cpp b/src/mvc/ScanRegionDialog.cpp index c72e9d9..6553960 100644 --- a/src/mvc/ScanRegionDialog.cpp +++ b/src/mvc/ScanRegionDialog.cpp @@ -16,6 +16,8 @@ ScanRegionDialog::ScanRegionDialog() : QDialog() { + _cbDelegate = new ComboBoxBoolDelegate(); + _cbDelegate->setCustomCol(1); _avail_scans = nullptr; _createLayout(); @@ -143,7 +145,13 @@ void ScanRegionDialog::onUpdateAndQueue() BlueskyPlan plan; plan.type = _scan_type->currentText(); _scan_table_model->getCurrentParams(plan); - plan.parameters[_cb_batch_prop->currentText()].default_val = QString::number(start); + for(auto &itr : plan.parameters) + { + if(itr.name == _cb_batch_prop->currentText()) + { + itr.default_val = QString::number(start); + } + } emit ScanUpdated(plan); start += inc; } @@ -166,12 +174,26 @@ void ScanRegionDialog::scanChanged(const QString &scan_name) { if(_avail_scans->count(scan_name) > 0) { - _scan_table_model->setAllData(_avail_scans->at(scan_name)); _cb_batch_prop->clear(); - BlueskyPlan plan = _avail_scans->at(scan_name); - for(auto itr : plan.parameters) + const BlueskyPlan plan = _avail_scans->at(scan_name); + _scan_table_model->setAllData(_avail_scans->at(scan_name)); + int idx = 0; + for(auto itr: plan.parameters) { - _cb_batch_prop->addItem(itr.first); + if(itr.default_val == "True" || itr.default_val == "False") + { + _scan_options->setItemDelegateForRow(idx, _cbDelegate); + } + else + { + // only add non strings + if(itr.default_val.count('"') == 0 && itr.default_val.count('\'') == 0) + { + _cb_batch_prop->addItem(itr.name); + } + _scan_options->setItemDelegateForRow(idx, nullptr); + } + idx++; } } } diff --git a/src/mvc/ScanRegionDialog.h b/src/mvc/ScanRegionDialog.h index d10fec8..2cf9155 100644 --- a/src/mvc/ScanRegionDialog.h +++ b/src/mvc/ScanRegionDialog.h @@ -20,6 +20,7 @@ #include "gstar/AnnotationProperty.h" #include "mvc/BlueskyPlan.h" #include "mvc/ScanTableModel.h" +#include "mvc/ComboBoxBoolDelegate.h" //--------------------------------------------------------------------------- @@ -91,6 +92,8 @@ public slots: std::map *_avail_scans; + ComboBoxBoolDelegate *_cbDelegate; + }; diff --git a/src/mvc/ScanTableModel.h b/src/mvc/ScanTableModel.h index 3dc46e5..6c7f099 100644 --- a/src/mvc/ScanTableModel.h +++ b/src/mvc/ScanTableModel.h @@ -38,7 +38,7 @@ class ScanTableModel : public QAbstractTableModel int rown = _data.size(); QModelIndex gIndex = index(rown, 0, QModelIndex()); beginInsertRows(gIndex, rown, rown); - _data.append(row); + _data.push_back(row); endInsertRows(); } @@ -60,10 +60,8 @@ class ScanTableModel : public QAbstractTableModel void getCurrentParams(BlueskyPlan& plan) { - for(auto itr : _data) - { - plan.parameters[itr.name] = itr; - } + plan.parameters.clear(); + plan.parameters = _data; } //--------------------------------------------------------------------------- @@ -89,9 +87,15 @@ class ScanTableModel : public QAbstractTableModel return rowData.description; }; } + else if(role == Qt::EditRole && index.column() == 1) + { + return rowData.default_val; + } return QVariant(); } + //--------------------------------------------------------------------------- + QVariant headerData(int section, Qt::Orientation orientation, int role) const override { // Check this is DisplayRole @@ -139,10 +143,7 @@ class ScanTableModel : public QAbstractTableModel { beginResetModel(); _data.clear(); - for(auto itr : scan.parameters) - { - _data.append(itr.second); - } + _data = scan.parameters; endResetModel(); } @@ -154,7 +155,23 @@ class ScanTableModel : public QAbstractTableModel { if( index.row() < _data.size() && index.column() == 1) { - _data[index.row()].default_val = value.toString(); + QString pre_val = _data[index.row()].default_val; + if(pre_val == "True" || pre_val == "False") + { + int cb_idx = value.toInt(); + if (cb_idx == 1) // index 0 = false, 1 = true + { + _data[index.row()].default_val = "True"; + } + else + { + _data[index.row()].default_val = "False"; + } + } + else + { + _data[index.row()].default_val = value.toString(); + } return true; } return false; @@ -165,7 +182,7 @@ class ScanTableModel : public QAbstractTableModel //--------------------------------------------------------------------------- private: - QList _data; + std::vector _data; QString _headers[3]; }; From a5f63dc2ec610a61366a46ebc24181dfd8b7c608 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Tue, 17 Dec 2024 11:20:00 -0600 Subject: [PATCH 09/11] Added bool delegate for True,False parameters for BlueSky --- src/mvc/ComboBoxBoolDelegate.cpp | 89 ++++++++++++++++++++++++++++++++ src/mvc/ComboBoxBoolDelegate.h | 42 +++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/mvc/ComboBoxBoolDelegate.cpp create mode 100644 src/mvc/ComboBoxBoolDelegate.h diff --git a/src/mvc/ComboBoxBoolDelegate.cpp b/src/mvc/ComboBoxBoolDelegate.cpp new file mode 100644 index 0000000..937969e --- /dev/null +++ b/src/mvc/ComboBoxBoolDelegate.cpp @@ -0,0 +1,89 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2012, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include + +#include + +//--------------------------------------------------------------------------- + +ComboBoxBoolDelegate::ComboBoxBoolDelegate(QObject *parent) : QItemDelegate(parent) +{ + Items = {"False", "True"}; + _custom_col = -1; +} + +//--------------------------------------------------------------------------- + +QWidget *ComboBoxBoolDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const +{ + QComboBox* editor = new QComboBox(parent); + for(unsigned int i = 0; i < Items.size(); ++i) + { + editor->addItem(Items[i].c_str()); + } + return editor; +} + +//--------------------------------------------------------------------------- + +void ComboBoxBoolDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + QComboBox *comboBox = static_cast(editor); + QString value = index.model()->data(index, Qt::EditRole).toString(); + if(value == "False") + { + comboBox->setCurrentIndex(0); + } + else + { + comboBox->setCurrentIndex(1); + } +} + +//--------------------------------------------------------------------------- + +void ComboBoxBoolDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QComboBox *comboBox = static_cast(editor); + model->setData(index, comboBox->currentIndex(), Qt::EditRole); +} + +//--------------------------------------------------------------------------- + +void ComboBoxBoolDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const +{ + editor->setGeometry(option.rect); +} + +//--------------------------------------------------------------------------- + +void ComboBoxBoolDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyleOptionViewItem myOption = option; + myOption.text = index.data().toString(); + if(_custom_col > -1 ) + { + if(_custom_col == index.column()) + { + QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter); + } + else + { + QItemDelegate::paint(painter, option, index); + } + } + else + { + QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter); + } +} + +//--------------------------------------------------------------------------- diff --git a/src/mvc/ComboBoxBoolDelegate.h b/src/mvc/ComboBoxBoolDelegate.h new file mode 100644 index 0000000..12f6b68 --- /dev/null +++ b/src/mvc/ComboBoxBoolDelegate.h @@ -0,0 +1,42 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2012, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#ifndef COMBO_BOX_BOOL_DELEGATE_H +#define COMBO_BOX_BOOL_DELEGATE_H + +//--------------------------------------------------------------------------- + +#include +#include + +#include +#include +#include +#include + +class ComboBoxBoolDelegate : public QItemDelegate +{ +Q_OBJECT +public: + ComboBoxBoolDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + + void setCustomCol(int col) {_custom_col = col;} + +private: + std::vector Items; + int _custom_col; +}; + +//--------------------------------------------------------------------------- + +#endif + +//--------------------------------------------------------------------------- From 53beeeab669703b9fec262f2610434b665ae9c11 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Mon, 6 Jan 2025 14:17:35 -0600 Subject: [PATCH 10/11] Changed int spectra x axis tick interval from 0.5 to 1.0 --- src/mvc/SpectraWidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mvc/SpectraWidget.cpp b/src/mvc/SpectraWidget.cpp index 7d329e4..e5199d3 100644 --- a/src/mvc/SpectraWidget.cpp +++ b/src/mvc/SpectraWidget.cpp @@ -71,9 +71,9 @@ void SpectraWidget::createLayout() _axisX->setLabelFormat("%.1f"); _axisX->setTruncateLabels(false); _axisX->setTickAnchor(0.0); - _axisX->setTickInterval(0.5); + _axisX->setTickInterval(1.0); _axisX->setTickType(QValueAxis::TicksDynamic); - _axisX->setTickCount(20); + //_axisX->setTickCount(10); _top_axis_elements = new QCategoryAxis(); //_top_axis_elements->setTickAnchor(0.0); From 28253c4cf28474027923e8b6dd97799a5579d003 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Tue, 7 Jan 2025 13:11:37 -0600 Subject: [PATCH 11/11] Added option to turn off building with opencv --- CMakeLists.txt | 44 +++++++++++++++++++- src/gstar/Annotation/RoiMaskGraphicsItem.cpp | 3 +- src/gstar/Annotation/RoiMaskGraphicsItem.h | 6 ++- src/mvc/ImageSegROIDialog.cpp | 6 ++- src/mvc/ImageSegROIDialog.h | 5 ++- src/mvc/SpectraWidget.cpp | 6 --- src/mvc/TIFF_Model.cpp | 10 ++++- 7 files changed, 65 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dcdfc8..c5a8ccb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ option(AVX2 "Compule with arch AVX2 on MSVC" OFF) option(AVX "Compule with arch AVX on MSVC" OFF) option(SSE2 "Compule with arch SSE2 on MSVC" OFF) option(MSVC_DEBUG_INFO_REL "Compule with debug info in Release build for MSVC" OFF) +option(BUILD_WITH_OPENCV_SUPPORT "Compule with opencv support for image segmentation" ON) IF (UNIX) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/linux) @@ -85,9 +86,13 @@ find_package(yaml-cpp CONFIG REQUIRED) find_package(cppzmq CONFIG REQUIRED) find_package(TIFF REQUIRED) find_package(XRF_Maps CONFIG REQUIRED COMPONENTS libxrf_io libxrf_fit) -find_package(OpenCV CONFIG REQUIRED) find_package(NLopt CONFIG REQUIRED) +IF (BUILD_WITH_OPENCV_SUPPORT) + add_definitions(-D_BUILD_WITH_OPENCV) + find_package(OpenCV CONFIG REQUIRED) +ENDIF() + if (libxrf_fit_FOUND) message("Found libxrf_fit") endif() @@ -213,6 +218,7 @@ IF (MSVC) set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS "/D_WINSOCKAPI_") set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS_RELEASE "/O2 /Qvec-report:2 /GL /MP /bigobj /Qansi-alias") set_target_properties(uProbeX PROPERTIES LINK_FLAGS "/LTCG") + IF (BUILD_WITH_OPENCV_SUPPORT) target_link_libraries (uProbeX PRIVATE yaml-cpp::yaml-cpp libzmq-static @@ -235,12 +241,32 @@ IF (MSVC) libxrf_io ${CMAKE_THREAD_LIBS_INIT} ws2_32.lib ) + ELSE() + target_link_libraries (uProbeX PRIVATE + yaml-cpp::yaml-cpp + libzmq-static + ws2_32.lib + rpcrt4.lib + iphlpapi.lib + ${TIFF_LIBRARIES} + ${Qt6Core_LIBRARIES} + ${Qt6Charts_LIBRARIES} + netCDF::netcdf + hdf5::hdf5-shared + cppzmq cppzmq-static + NLopt::nlopt + libxrf_fit + libxrf_io + ${CMAKE_THREAD_LIBS_INIT} + ws2_32.lib ) + ENDIF() + ELSEIF (UNIX) #IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # set_target_properties(uProbeX PROPERTIES MACOSX_BUNDLE TRUE) #ENDIF() set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS "-O2") - + IF (BUILD_WITH_OPENCV_SUPPORT) target_link_libraries (uProbeX PRIVATE libzmq yaml-cpp::yaml-cpp @@ -258,4 +284,18 @@ ELSEIF (UNIX) libxrf_fit libxrf_io ${CMAKE_THREAD_LIBS_INIT} ) + ELSE() + target_link_libraries (uProbeX PRIVATE + libzmq + yaml-cpp::yaml-cpp + ${TIFF_LIBRARIES} + ${Qt6Core_LIBRARIES} + ${Qt6Charts_LIBRARIES} + netCDF::netcdf + cppzmq cppzmq-static + NLopt::nlopt + libxrf_fit + libxrf_io + ${CMAKE_THREAD_LIBS_INIT} ) + ENDIF() ENDIF() diff --git a/src/gstar/Annotation/RoiMaskGraphicsItem.cpp b/src/gstar/Annotation/RoiMaskGraphicsItem.cpp index 68b3e6f..2c42249 100644 --- a/src/gstar/Annotation/RoiMaskGraphicsItem.cpp +++ b/src/gstar/Annotation/RoiMaskGraphicsItem.cpp @@ -17,6 +17,7 @@ using namespace gstar; static const QString CONST_STATIC_ROI_NAME = QString("ROI"); +#ifdef _BUILD_WITH_OPENCV RoiMaskGraphicsItem::RoiMaskGraphicsItem(cv::Mat& mat, int idx, QColor col, AbstractGraphicsItem* parent) : AbstractGraphicsItem(parent) { @@ -41,7 +42,7 @@ RoiMaskGraphicsItem::RoiMaskGraphicsItem(cv::Mat& mat, int idx, QColor col, Abst _init(col, 70); } - +#endif //----------------------------------------------------------------------------- diff --git a/src/gstar/Annotation/RoiMaskGraphicsItem.h b/src/gstar/Annotation/RoiMaskGraphicsItem.h index d84c15e..ea0ed2f 100644 --- a/src/gstar/Annotation/RoiMaskGraphicsItem.h +++ b/src/gstar/Annotation/RoiMaskGraphicsItem.h @@ -10,8 +10,9 @@ #include "gstar/Annotation/AbstractGraphicsItem.h" #include "gstar/RectItem.h" +#ifdef _BUILD_WITH_OPENCV #include - +#endif //--------------------------------------------------------------------------- namespace gstar @@ -34,8 +35,9 @@ class RoiMaskGraphicsItem : public AbstractGraphicsItem * @param parent */ // blank constructor for classid +#ifdef _BUILD_WITH_OPENCV RoiMaskGraphicsItem(cv::Mat& mat, int idx, QColor col, AbstractGraphicsItem* parent = 0); - +#endif RoiMaskGraphicsItem(int rows, int cols, QColor col, AbstractGraphicsItem* parent = 0); RoiMaskGraphicsItem(QImage mask, QColor color, int alpha, AbstractGraphicsItem* parent = 0); diff --git a/src/mvc/ImageSegROIDialog.cpp b/src/mvc/ImageSegROIDialog.cpp index 3206f3b..074e5c8 100644 --- a/src/mvc/ImageSegROIDialog.cpp +++ b/src/mvc/ImageSegROIDialog.cpp @@ -10,9 +10,9 @@ #include #include #include +#ifdef _BUILD_WITH_OPENCV #include -//#include // out in version 4.10 - +#endif //--------------------------------------------------------------------------- static const QString STR_KMEANS = QString("KMeans"); static const QString STR_DBSCAN = QString("DBSCAN"); @@ -501,6 +501,7 @@ void ImageSegRoiDialog::onRun() ArrayXXr int_img; _get_img(int_img, _chk_normalize_sum->isChecked()); + #ifdef _BUILD_WITH_OPENCV if(_techTabs->currentIndex() == 0) // KMEANS { cv::KmeansFlags flags; @@ -568,6 +569,7 @@ void ImageSegRoiDialog::onRun() cv::Ptr< cv::ximgproc::ScanSegment > scanSeg = cv::ximgproc::createScanSegment(int_img.cols(), int_img.rows(), 1, slices=8, merge_small); */ } + #endif _acceptBtn->setEnabled(true); } diff --git a/src/mvc/ImageSegROIDialog.h b/src/mvc/ImageSegROIDialog.h index 8cd3fb6..9a707c1 100644 --- a/src/mvc/ImageSegROIDialog.h +++ b/src/mvc/ImageSegROIDialog.h @@ -23,9 +23,12 @@ #include #include "data_struct/fit_parameters.h" #include +#include "gstar/Annotation/RoiMaskGraphicsItem.h" +#ifdef _BUILD_WITH_OPENCV #include #include -#include "gstar/Annotation/RoiMaskGraphicsItem.h" +#endif + //--------------------------------------------------------------------------- diff --git a/src/mvc/SpectraWidget.cpp b/src/mvc/SpectraWidget.cpp index e5199d3..40f5339 100644 --- a/src/mvc/SpectraWidget.cpp +++ b/src/mvc/SpectraWidget.cpp @@ -76,18 +76,12 @@ void SpectraWidget::createLayout() //_axisX->setTickCount(10); _top_axis_elements = new QCategoryAxis(); - //_top_axis_elements->setTickAnchor(0.0); - //_top_axis_elements->setTickInterval(0.5); - //_top_axis_elements->setTickType(QValueAxis::TicksDynamic); - //_top_axis_elements->setTickCount(20); _top_axis_elements->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); _top_axis_elements->setGridLineVisible(false); _axisY = new QValueAxis(); _axisY->setTitleText("Counts"); _axisY->setLabelFormat("%i"); - //_axisY->setTickCount(series->count()); - _chart = new QChart(); _chart->addAxis(_axisX, Qt::AlignBottom); diff --git a/src/mvc/TIFF_Model.cpp b/src/mvc/TIFF_Model.cpp index 6ba8042..65b9a8a 100644 --- a/src/mvc/TIFF_Model.cpp +++ b/src/mvc/TIFF_Model.cpp @@ -10,8 +10,11 @@ #include #include + +#ifdef _BUILD_WITH_OPENCV #include #include +#endif using gstar::LinearTransformer; @@ -56,6 +59,7 @@ bool TIFF_Model::load(QString filepath) } else { + #ifdef _BUILD_WITH_OPENCV cv::Mat mat = cv::imread(filepath.toStdString(), cv::IMREAD_GRAYSCALE | cv::IMREAD_ANYDEPTH); if (mat.rows > 0 && mat.cols > 0) { @@ -113,7 +117,7 @@ bool TIFF_Model::load(QString filepath) } } } - + #endif } } catch (std::string& s) @@ -211,6 +215,7 @@ int TIFF_Model::getRank() bool TIFF_Model::save_img(QString filename) { + #ifdef _BUILD_WITH_OPENCV QImageWriter writer(filename); if (false == writer.write(_img)) { @@ -239,6 +244,9 @@ bool TIFF_Model::save_img(QString filename) } } return true; + #else + return false; + #endif } //--------------------------------------------------------------------------- \ No newline at end of file