Skip to content

Commit

Permalink
Remove python solver for now. Will refactor it in later
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Jul 15, 2024
1 parent bd6104c commit d7ff084
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 91 deletions.
90 changes: 47 additions & 43 deletions src/mvc/SolverProfileWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <QRadioButton>
#include <QMessageBox>

#include <core/PythonLoader.h>
//#include <core/PythonLoader.h>

//---------------------------------------------------------------------------

Expand All @@ -23,7 +23,7 @@ SolverProfileWidget::SolverProfileWidget(QWidget* parent) : QDialog(parent)
m_currentProfileIndex = 0;
m_coordPoints = nullptr;
m_solverWidget = nullptr;
m_solver = nullptr;
//m_solver = nullptr;
createCompontent();
createLayOut();
addDefaultTransformers();
Expand All @@ -49,8 +49,8 @@ void SolverProfileWidget::addProfileItem(QString name, QString desc)

m_profiles.push_back(profile);

m_pythonSolverWidget -> removeCoefficientItems();
m_pythonSolverWidget -> removeOptionItems();
_solverParamWidget -> removeCoefficientItems();
_solverParamWidget -> removeOptionItems();

}

Expand Down Expand Up @@ -95,8 +95,8 @@ void SolverProfileWidget::addProfile(QString name, QString desc, QMap<QString, d
SLOT(addProfileItem(QString, QString)));
}

m_pythonSolverWidget->removeCoefficientItems();
m_pythonSolverWidget->removeOptionItems();
_solverParamWidget->removeCoefficientItems();
_solverParamWidget->removeOptionItems();

}

Expand All @@ -107,7 +107,7 @@ void SolverProfileWidget::coefficientItemChanged()
{
if(m_profiles.size() > 0)
{
m_profiles[m_currentProfileIndex].setCoefficientAttrs(m_pythonSolverWidget -> getCoefficientAttrsList());
m_profiles[m_currentProfileIndex].setCoefficientAttrs(_solverParamWidget -> getCoefficientAttrsList());
}
}

Expand Down Expand Up @@ -135,12 +135,12 @@ void SolverProfileWidget::createCompontent()
this,
SLOT(switchProfileItem(const QItemSelection&, const QItemSelection&)));

m_pythonSolverWidget = new SolverParameterWidget();
connect(m_pythonSolverWidget,
_solverParamWidget = new SolverParameterWidget();
connect(_solverParamWidget,
SIGNAL(coefficientItemChanged()),
this,
SLOT(coefficientItemChanged()));
connect(m_pythonSolverWidget,
connect(_solverParamWidget,
SIGNAL(optionItemChanged()),
this,
SLOT(optionItemChanged()));
Expand All @@ -151,7 +151,7 @@ void SolverProfileWidget::createCompontent()

m_lblPofileTable = new QLabel("Profile:");
m_lblPofileTable->setFont(font);

/*
m_lblOpenPthon = new QLabel("Python Script Path:");
m_lblOpenPthon->setFont(font);
Expand All @@ -168,6 +168,7 @@ void SolverProfileWidget::createCompontent()
m_lblTitle->setFont(font);
m_pythonFuncName = new QLineEdit("");
*/
}

//---------------------------------------------------------------------------
Expand All @@ -176,9 +177,10 @@ 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() );
}

//---------------------------------------------------------------------------
Expand All @@ -190,6 +192,7 @@ void SolverProfileWidget::createLayOut()
mainLayout->addRow(m_lblPofileTable);
mainLayout->addRow(m_profileTable);

/*
mainLayout->addRow(m_lblOpenPthon);
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->addWidget(m_openPythonButton);
Expand All @@ -200,8 +203,8 @@ void SolverProfileWidget::createLayOut()
// mainLayout->addRow(m_pythonFuncName);
mainLayout->addRow(
new QLabel("The python solver must have solver and transform functions !"));
mainLayout->addRow(m_pythonSolverWidget);

*/
mainLayout->addRow(_solverParamWidget);
m_btnRunSolver = new QPushButton("Run Solver");
connect(m_btnRunSolver,
SIGNAL(pressed()),
Expand Down Expand Up @@ -329,14 +332,14 @@ QStringList SolverProfileWidget::getProfileOptionAttrs()
SolverParameterWidget* SolverProfileWidget::getPythonSolverProfileWiget()
{

return m_pythonSolverWidget;
return _solverParamWidget;
}

//---------------------------------------------------------------------------

void SolverProfileWidget::openPythonFile()
{

/*
m_fileName = QFileDialog::getOpenFileName(this,
"Open python script", ".",
tr("py (*.py *.PY)"));
Expand All @@ -348,7 +351,7 @@ void SolverProfileWidget::openPythonFile()
m_filePath = m_fileInfo.canonicalFilePath();
m_lePythonPath->setText(m_filePath);
//m_lePythonPath->setText(m_filePath);
if(m_profiles.size() < 1)
{
Expand Down Expand Up @@ -384,8 +387,8 @@ void SolverProfileWidget::openPythonFile()
}
m_profiles[m_currentProfileIndex].setCoefficientAttrs(coefList);
m_profileTable->setRow(m_currentProfileIndex);
m_pythonSolverWidget->removeCoefficientItems();
m_pythonSolverWidget->addCoefficientItems(m_profiles[m_currentProfileIndex].getCoefficientAttrs());
_solverParamWidget->removeCoefficientItems();
_solverParamWidget->addCoefficientItems(m_profiles[m_currentProfileIndex].getCoefficientAttrs());
}
Expand All @@ -408,8 +411,8 @@ void SolverProfileWidget::openPythonFile()
optionsList.append(attr);
}
m_profiles[m_currentProfileIndex].setOptionAttrs(optionsList);
m_pythonSolverWidget->removeOptionItems();
m_pythonSolverWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs());
_solverParamWidget->removeOptionItems();
_solverParamWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs());
}
m_profileTable->setRow(m_currentProfileIndex);
Expand All @@ -420,6 +423,7 @@ void SolverProfileWidget::openPythonFile()
logE<<ex.what();
QMessageBox::warning(nullptr, "Error loading variables", "Error loading variables. You will have to manually enter them.");
}
*/
}

//---------------------------------------------------------------------------
Expand All @@ -428,8 +432,7 @@ void SolverProfileWidget::optionItemChanged()
{
if(m_profiles.size() > 0)
{
m_profiles[m_currentProfileIndex].setOptionAttrs(
m_pythonSolverWidget -> getOptionAttrsList());
m_profiles[m_currentProfileIndex].setOptionAttrs(_solverParamWidget -> getOptionAttrsList());
}
}

Expand All @@ -438,8 +441,8 @@ void SolverProfileWidget::optionItemChanged()
void SolverProfileWidget::removeProfileItem(int selectRow)
{

m_pythonSolverWidget -> removeCoefficientItems();
m_pythonSolverWidget -> removeOptionItems();
_solverParamWidget -> removeCoefficientItems();
_solverParamWidget -> removeOptionItems();

m_profiles.erase(m_profiles.begin() + selectRow);

Expand All @@ -460,9 +463,9 @@ void SolverProfileWidget::removeProfileItem(int selectRow)

setPythonSolverName(m_profiles[m_currentProfileIndex].getFilePath());

m_pythonSolverWidget->addCoefficientItems(m_profiles[m_currentProfileIndex].getCoefficientAttrs());
_solverParamWidget->addCoefficientItems(m_profiles[m_currentProfileIndex].getCoefficientAttrs());

m_pythonSolverWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs());
_solverParamWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs());


}
Expand Down Expand Up @@ -559,7 +562,7 @@ void SolverProfileWidget::setPythonSolverName(QString fileName)

m_filePath = m_fileInfo.canonicalFilePath();

m_lePythonPath->setText(m_filePath);
//m_lePythonPath->setText(m_filePath);

}

Expand All @@ -579,8 +582,8 @@ void SolverProfileWidget::switchProfileItem(const QItemSelection& selected,

Q_UNUSED(deselected);

m_pythonSolverWidget -> removeCoefficientItems();
m_pythonSolverWidget -> removeOptionItems();
_solverParamWidget -> removeCoefficientItems();
_solverParamWidget -> removeOptionItems();


QModelIndex index = list.at(0);
Expand All @@ -589,9 +592,9 @@ void SolverProfileWidget::switchProfileItem(const QItemSelection& selected,

setPythonSolverName(m_profiles[m_currentProfileIndex].getFilePath());

m_pythonSolverWidget->addCoefficientItems(m_profiles[m_currentProfileIndex].getCoefficientAttrs());
_solverParamWidget->addCoefficientItems(m_profiles[m_currentProfileIndex].getCoefficientAttrs());

m_pythonSolverWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs());
_solverParamWidget->addOptionItems(m_profiles[m_currentProfileIndex].getOptionAttrs());

}

Expand All @@ -606,6 +609,7 @@ void SolverProfileWidget::runSolver()

emit solverStart();

/*
if(m_solver == nullptr)
{
m_solver = new PythonSolver();
Expand All @@ -617,18 +621,18 @@ void SolverProfileWidget::runSolver()
}
m_solver->setCoordPoints(*m_coordPoints);

*/
QMap<QString, double> newMinCoefs;
QMap<QString, double> minCoefs = m_pythonSolverWidget->getSelectedCoefficientAttrsMap();

m_solver->setAllCoef(m_pythonSolverWidget->getCoefficientAttrsMap());
m_solver->setOptions(m_pythonSolverWidget->getOptionAttrsMap());
QMap<QString, double> minCoefs = _solverParamWidget->getSelectedCoefficientAttrsMap();
/*
m_solver->setAllCoef(_solverParamWidget->getCoefficientAttrsMap());
m_solver->setOptions(_solverParamWidget->getOptionAttrsMap());
m_solver->setMinCoef(minCoefs);

*/


QApplication::setOverrideCursor(Qt::WaitCursor);
bool retVal = m_solver->run();
// bool retVal = m_solver->run();
QApplication::restoreOverrideCursor();

if(m_solverWidget != nullptr)
Expand All @@ -646,10 +650,10 @@ void SolverProfileWidget::runSolver()
this,
SLOT(cancelUpdatedSolverVariables()));

newMinCoefs = m_solver->getMinCoef();
// newMinCoefs = m_solver->getMinCoef();
m_solverWidget->setCoefs(minCoefs, newMinCoefs);
m_solverWidget->setStatusString(m_solver->getLastErrorMessage());

// m_solverWidget->setStatusString(m_solver->getLastErrorMessage());
/*
if(retVal)
{
m_solverWidget->setUseBtnEnabled(true);
Expand All @@ -658,7 +662,7 @@ void SolverProfileWidget::runSolver()
{
m_solverWidget->setUseBtnEnabled(false);
}

*/
m_solverWidget->show();

}
Expand Down
62 changes: 14 additions & 48 deletions src/mvc/SolverProfileWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
#include <preferences/ProfileTable.h>
#include <preferences/Profile.h>
#include <preferences/SolverParameterWidget.h>
#include <solver/PythonSolver.h>
//#include <solver/PythonSolver.h>
#include <mvc/SolverWidget.h>
#include <solver/SV_CoordTransformer.h>
#include <gstar/LinearTransformer.h>
#include <solver/LinearCoordTransformer.h>


const QString QSTR_2IDE_COORD_TRANS = "2IDE Coordinate Transform";
const QString QSTR_2IDE_COORD_TRANS_DESC = "Coordiante transform for translating from Visible light microscope to X-Ray microprobe.";
const QString QSTR_LINEAR_COORD_TRANS = "Linear Coordinate Transform";
const QString QSTR_LINEAR_COORD_TRANS_DESC = "General Linear Coordinate Transform";
const QString QSTR_LINEAR_COORD_TRANS_2 = "Linear Coordinate Transform 2";
const QString QSTR_LINEAR_COORD_TRANS_DESC_2 = "General Linear Coordinate Transform with extra slope";



//---------------------------------------------------------------------------

Expand Down Expand Up @@ -208,59 +213,23 @@ private slots:
*/
ProfileTable* m_profileTable;

/**
* @brief m_openPythonAction
*/
QPushButton* m_openPythonButton;

/**
* @brief m_lblOpenPthon
*/
QLabel* m_lblOpenPthon;
//QPushButton* m_openPythonButton;
//QLabel* m_lblOpenPthon;
//QLabel* m_lblP;

/**
* @brief m_lblP
*/
QLabel* m_lblP;

/**
* @brief m_lblPofileTable
*/
QLabel* m_lblPofileTable;

/**
* @brief m_lblTitle
*/
QLabel* m_lblTitle;

//QLineEdit* m_pythonFuncName;
//QLineEdit* m_lePythonPath;

/**
* @brief m_pythonFuncName
*/
QLineEdit* m_pythonFuncName;

/**
* @brief m_lePythonPath
*/
QLineEdit* m_lePythonPath;

/**
* @brief m_profiles
*/
std::vector<Profile> m_profiles;

/**
* @brief m_fileName
*/
QString m_fileName;

/**
* @brief m_filePath
*/
QString m_filePath;

/**
* @brief m_fileInfo
*/
QFileInfo m_fileInfo;

QPushButton *m_btnRunSolver;
Expand All @@ -269,12 +238,9 @@ private slots:

QPushButton *m_btnCancel;

/**
* @brief m_pythonSolverTable
*/
SolverParameterWidget* m_pythonSolverWidget;
SolverParameterWidget* _solverParamWidget;

PythonSolver *m_solver;
//PythonSolver *m_solver;

QList< QMap<QString, double> > *m_coordPoints;

Expand Down

0 comments on commit d7ff084

Please sign in to comment.