Commit 7456bcdc authored by Huff, Israel's avatar Huff, Israel
Browse files

- removed APTEnsWidget and APTEnsDataModel from the example (not relevant to...

- removed APTEnsWidget and APTEnsDataModel from the example (not relevant to it and previously moved to another project)
- more changes to support SFTPFile and SFTPDir usage
- added functionality to GUI to demonstrate SFTPFile and SFTPDir usage (although the latter is not yet working)
parent ca863a5c
Pipeline #100125 failed with stages
in 5 minutes and 11 seconds
......@@ -306,11 +306,13 @@ ssize_t SFTPFile::tell()
class SFTPDirImpl
{
public:
sftp_dir dir = nullptr;
sftp_dir dir = nullptr;
sftp_session sftp = nullptr;
explicit SFTPDirImpl(sftp_session sftpSession, QString dirName)
{
dir = sftp_opendir(sftpSession, dirName.toStdString().c_str());
dir = sftp_opendir(sftpSession, dirName.toStdString().c_str());
sftp = sftpSession;
}
~SFTPDirImpl()
......@@ -338,7 +340,7 @@ bool SFTPDir::hasNext() { return (0 == sftp_dir_eof(p->dir)); }
// caller is responsible for deleting returned SFTPAttributes structure
SFTPAttributes* SFTPDir::next()
{
sftp_attributes sftpResult = sftp_readdir(p->dir->sftp, p->dir);
sftp_attributes sftpResult = sftp_readdir(p->sftp, p->dir);
if (nullptr == sftpResult) return nullptr;
SFTPAttributes* retVal = new SFTPAttributes;
......@@ -376,7 +378,8 @@ bool SFTPDir::close()
int rc = sftp_closedir(p->dir);
if (SSH_NO_ERROR == rc)
{
p->dir = nullptr;
p->dir = nullptr;
p->sftp = nullptr;
return true;
}
return false;
......
......@@ -127,6 +127,8 @@ QByteArray SessionController::readExecOutput()
return p->worker->readExecOutput();
}
Session* SessionController::session() { return p->worker->session(); }
void SessionController::setHost(QString host) { emit setHostRequested(host); }
void SessionController::setLogVerbosity(SessionVerbosity level)
......
......@@ -4,6 +4,7 @@
#include <QObject>
#include "rsmcore/declspec.hh"
#include "rsmcore/session.hh"
#include "rsmcore/sessionlog.hh"
#include <memory>
......@@ -30,6 +31,7 @@ class RSM_PUBLIC SessionController : public QObject
~SessionController();
QByteArray readExecOutput();
Session* session();
public slots:
......
#include "rsmcore/sessionworker.hh"
#include "radixbug/bug.hh"
#include "rsmcore/session.hh"
#include <cassert>
#include <sstream>
......@@ -16,8 +15,8 @@ class SessionWorkerImpl
private:
// privatize copy of this object to prevent their use.
// would be nice to use c++14 '= delete' but c'est la vie.
SessionWorkerImpl(const SessionWorkerImpl& orig) { void(sizeof(orig)); };
void operator=(const SessionWorkerImpl& orig) { void(sizeof(orig)); };
SessionWorkerImpl(const SessionWorkerImpl& orig) { void(sizeof(orig)); }
void operator=(const SessionWorkerImpl& orig) { void(sizeof(orig)); }
public:
Session* session = nullptr;
......@@ -61,6 +60,8 @@ SessionWorker::~SessionWorker()
QByteArray SessionWorker::readExecOutput() { return p->output_buffer; }
Session* SessionWorker::session() { return p->session; }
void SessionWorker::setHost(QString host) { p->session->setHost(host); }
void SessionWorker::setLogVerbosity(SessionVerbosity level)
{
......
......@@ -4,6 +4,7 @@
#include <QObject>
#include "rsmcore/declspec.hh"
#include "rsmcore/session.hh"
#include "rsmcore/sessionlog.hh"
namespace rsm
......@@ -30,6 +31,7 @@ class RSM_PUBLIC SessionWorker : public QObject
SessionWorker(QString host, QObject* parent = nullptr);
~SessionWorker();
QByteArray readExecOutput();
Session* session();
public slots:
......
SET(PORTAL_HEADERS
rsmportalexample.hh
aptenswidget.hh
aptensdatamodel.hh
settings.hh
)
QT5_WRAP_CPP(PORTAL_MOC_FILES
......@@ -13,8 +11,6 @@ TRIBITS_ADD_EXECUTABLE(rsmportalexample
NOEXEPREFIX
SOURCES
rsmportalexample.cc
aptensdatamodel.cc
aptenswidget.cc
settings.cc
${PORTAL_MOC_FILES} ${PORTAL_HEADERS}
)
#include "aptensdatamodel.hh"
using namespace AptEns;
const QMap<Sampling, QString> APTEnsDataModel::sampleStrings = {
{Sampling::uniform, "uniform"}, {Sampling::gaussian, "gaussian"}};
const QMap<SoilType, QString> APTEnsDataModel::soilTypeStrings = {
{SoilType::siliceous, "siliceous"}, {SoilType::calcareous, "calcareous"}};
const QMap<FissionID, QString> APTEnsDataModel::fissionIDStrings = {
{FissionID::u235fi, "u235fi"}, {FissionID::u238fi, "u238fi"},
{FissionID::pu239fi, "pu239fi"}, {FissionID::u235he, "u235he"},
{FissionID::u238he, "u238he"}, {FissionID::pu239he, "pu239he"}};
#ifndef RSM_RSMWIDGETSEXAMPLE_APTENSDATAMODEL_HH_
#define RSM_RSMWIDGETSEXAMPLE_APTENSDATAMODEL_HH_
#include <QMap>
#include <QString>
#include <QStringList>
namespace AptEns
{
enum class Sampling
{
uniform,
gaussian
};
enum class SoilType
{
siliceous,
calcareous
};
enum class FissionID
{
u235fi,
u238fi,
pu239fi,
u235he,
u238he,
pu239he
};
class APTEnsDataModel
{
private:
double mLatitude = 0.;
double mLongitude = 0.;
double mAltitude = 0.;
SoilType mSoilType = SoilType::siliceous;
FissionID mFissionID = FissionID::u235fi;
double mTotalYield = 0.;
bool mYieldDefEnsemble = false;
unsigned mNumYields = 0;
double mMinYield = 0.;
double mMaxYield = 0.;
Sampling mYieldSampling = Sampling::uniform;
double mHeightOfBurst = 0.;
bool mHOBDefEnsemble = false;
unsigned mNumHOBs = 0;
double mMinHOB = 0.;
double mMaxHOB = 0.;
Sampling mHOBSampling = Sampling::uniform;
QStringList mMetFileSets;
QStringList mSetupCfgs;
unsigned mTurbEnsNum = 0;
unsigned mMetEnsNum = 0;
public:
// map strings to enum items
static const QMap<Sampling, QString> sampleStrings;
static const QMap<SoilType, QString> soilTypeStrings;
static const QMap<FissionID, QString> fissionIDStrings;
// returns double value on success or 0. on failure
static double textFieldToDouble(const QString &str)
{
if (str.trimmed().isEmpty()) return 0.;
bool ok;
double value = str.toDouble(&ok);
if (ok) return value;
return 0.;
}
static QString doubleToTextField(double value)
{
return QString::number(value);
}
// returns unsigned value on success or 0 on failure
static unsigned textFieldToUnsigned(const QString &str)
{
if (str.trimmed().isEmpty()) return 0;
bool ok;
int value = str.toInt(&ok);
if (ok && value >= 0) return static_cast<unsigned>(value);
return 0;
}
// getters
double latitude() { return mLatitude; }
double longitude() { return mLongitude; }
double altitude() { return mAltitude; }
SoilType soilType() { return mSoilType; }
FissionID fissionID() { return mFissionID; }
double totalYield() { return mTotalYield; }
bool yieldDefEnsemble() { return mYieldDefEnsemble; }
unsigned numYields() { return mNumYields; }
double minYield() { return mMinYield; }
double maxYield() { return mMaxYield; }
Sampling yieldSampling() { return mYieldSampling; }
double heightOfBurst() { return mHeightOfBurst; }
bool hobDefEnsemble() { return mHOBDefEnsemble; }
unsigned numHOBs() { return mNumHOBs; }
double minHOB() { return mMinHOB; }
double maxHOB() { return mMaxHOB; }
Sampling hobSampling() { return mHOBSampling; }
QStringList &metFileSets() { return mMetFileSets; }
QStringList &setupCfgs() { return mSetupCfgs; }
unsigned turbEnsNum() { return mTurbEnsNum; }
unsigned metEnsNum() { return mMetEnsNum; }
// setters
void setLatitude(double a) { mLatitude = a; }
void setLongitude(double a) { mLongitude = a; }
void setAltitude(double a) { mAltitude = a; }
void setSoilType(SoilType a) { mSoilType = a; }
void setFissionID(FissionID a) { mFissionID = a; }
void setTotalYield(double a) { mTotalYield = a; }
void setYieldDefEnsemble(bool a) { mYieldDefEnsemble = a; }
void setNumYields(unsigned a) { mNumYields = a; }
void setMinYield(double a) { mMinYield = a; }
void setMaxYield(double a) { mMaxYield = a; }
void setYieldSampling(Sampling a) { mYieldSampling = a; }
void setHeightOfBurst(double a) { mHeightOfBurst = a; }
void setHOBDefEnsemble(bool a) { mHOBDefEnsemble = a; }
void setNumHOBs(unsigned a) { mNumHOBs = a; }
void setMinHOB(double a) { mMinHOB = a; }
void setMaxHOB(double a) { mMaxHOB = a; }
void setHOBSampling(Sampling a) { mHOBSampling = a; }
void setTurbEnsNum(unsigned a) { mTurbEnsNum = a; }
void setMetEnsNum(unsigned a) { mMetEnsNum = a; }
};
} // namespace AptEns
#endif // RSM_RSMWIDGETSEXAMPLE_APTENSDATAMODEL_HH_
This diff is collapsed.
#ifndef RSM_RSMWIDGETSEXAMPLE_APTENSWIDGET_HH_
#define RSM_RSMWIDGETSEXAMPLE_APTENSWIDGET_HH_
#include <QCheckBox>
#include <QComboBox>
#include <QGroupBox>
#include <QKeyEvent>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QMenu>
#include <QMenuBar>
#include <QPushButton>
#include "aptensdatamodel.hh"
namespace AptEns
{
class StyledLabel : public QLabel
{
public:
StyledLabel(const QString &title, QWidget *parent = Q_NULLPTR);
};
class CenterTitleGroupBox : public QGroupBox
{
public:
CenterTitleGroupBox(const QString &title, QWidget *parent = Q_NULLPTR);
};
class LeftTitleGroupBox : public QGroupBox
{
public:
LeftTitleGroupBox(const QString &title, QWidget *parent = Q_NULLPTR);
};
class LineEditFocusSelectAll : public QLineEdit
{
public:
LineEditFocusSelectAll(QWidget *parent = Q_NULLPTR);
LineEditFocusSelectAll(const QString &text, QWidget *parent = Q_NULLPTR);
protected:
void focusInEvent(QFocusEvent *event) override;
};
class EditableListWidget : public QListWidget
{
Q_OBJECT
public:
EditableListWidget(QWidget *parent = nullptr)
: QListWidget(parent)
{
}
protected:
void keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Delete:
{
emit sigRemoveItem();
break;
}
case Qt::Key_Enter:
case Qt::Key_Return:
{
emit sigEditItem();
break;
}
default:
QListWidget::keyPressEvent(event);
}
}
void mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::MouseButton::LeftButton)
{
emit sigEditItem();
return;
}
QListWidget::mouseDoubleClickEvent(event);
}
signals:
void sigEditItem();
void sigRemoveItem();
};
class APTEnsWidget : public QWidget
{
Q_OBJECT
private:
QMap<QString, APTEnsDataModel> mDataModels;
QString mCurrentModel;
QString mCurrentFile;
QMenu *mFileMenu;
QMenu *mHelpMenu;
CenterTitleGroupBox *mSelectModelBox;
CenterTitleGroupBox *mCurrentModelBox;
QPushButton *mNewModelButton;
EditableListWidget *mModelListWidget;
CenterTitleGroupBox *mEventDefBox;
CenterTitleGroupBox *mYieldEnsBox;
CenterTitleGroupBox *mHeightOfBurstEnsBox;
CenterTitleGroupBox *mMeteorologyBox;
CenterTitleGroupBox *mDispPhysEnsBox;
CenterTitleGroupBox *mTurbEnsBox;
CenterTitleGroupBox *mMetEnsBox;
StyledLabel *mLatLabel;
LineEditFocusSelectAll *mLatLineEdit;
StyledLabel *mLonLabel;
LineEditFocusSelectAll *mLonLineEdit;
StyledLabel *mAltLabel;
LineEditFocusSelectAll *mAltLineEdit;
StyledLabel *mSoilTypeLabel;
QComboBox *mSoilTypeComboBox;
StyledLabel *mFissionIDLabel;
QComboBox *mFissionIDComboBox;
StyledLabel *mTotalYieldLabel;
LineEditFocusSelectAll *mTotalYieldLineEdit;
QCheckBox *mYieldDefineEnsCheckBox;
StyledLabel *mNumYieldsLabel;
LineEditFocusSelectAll *mNumYieldsLineEdit;
StyledLabel *mMinYieldLabel;
LineEditFocusSelectAll *mMinYieldLineEdit;
StyledLabel *mMaxYieldLabel;
LineEditFocusSelectAll *mMaxYieldLineEdit;
StyledLabel *mYieldSamplingLabel;
QComboBox *mYieldSamplingComboBox;
StyledLabel *mHOBLabel;
LineEditFocusSelectAll *mHOBLineEdit;
QCheckBox *mHOBDefineEnsCheckBox;
StyledLabel *mNumHOBsLabel;
LineEditFocusSelectAll *mNumHOBsLineEdit;
StyledLabel *mMinHOBLabel;
LineEditFocusSelectAll *mMinHOBLineEdit;
StyledLabel *mMaxHOBLabel;
LineEditFocusSelectAll *mMaxHOBLineEdit;
StyledLabel *mHOBSamplingLabel;
QComboBox *mHOBSamplingComboBox;
LeftTitleGroupBox *mMetFileSetsBox;
QListWidget *mMetFileSetsListWidget;
QPushButton *mMetAddSetButton;
QPushButton *mMetRemoveSetButton;
QPushButton *mMetAddButton;
QPushButton *mMetRemoveButton;
LeftTitleGroupBox *mSetupCfgsBox;
QListWidget *mSetupCfgsListWidget;
QPushButton *mSetupCfgsImportButton;
QPushButton *mSetupCfgsRemoveButton;
StyledLabel *mTurbEnsNumLabel;
LineEditFocusSelectAll *mTurbEnsNumLineEdit;
StyledLabel *mMetEnsNumLabel;
LineEditFocusSelectAll *mMetEnsNumLineEdit;
void createMenus(QMenuBar *menuBar);
void resetWindowTitle();
void updateGUIFromDataModel();
void addNewEnsemble();
public:
APTEnsWidget(QWidget *parent = nullptr);
public slots:
void openEnsembleEvent();
void saveEnsembleEvent();
void saveAsEnsembleEvent();
void closeEnsembleEvent();
void settingsEvent();
void exitEvent();
void aboutEvent();
void yieldDefineEnsStateChange(int state);
void hobDefineEnsStateChange(int state);
void addMeteorologyFile();
void removeMeteorologyFile();
void importSetupCfgFile();
void removeSetupCfgtFile();
};
} // namespace AptEns
#endif // RSM_RSMWIDGETSEXAMPLE_APTENSWIDGET_HH_
......@@ -5,7 +5,8 @@
* Created on June 24, 2018, 10:52 AM
*/
#include "rsmportalexample.hh"
#include <fcntl.h>
#include <QApplication>
#include <QGridLayout>
#include <QHBoxLayout>
......@@ -13,6 +14,7 @@
#include <QLabel>
#include <QMessageBox>
#include <QTabWidget>
#include "rsmportalexample.hh"
#include "radixbug/bug.hh"
using namespace rsm;
......@@ -47,8 +49,11 @@ ExamplePortalWidget::ExamplePortalWidget(QWidget *parent)
mDeleteJobButton = new QPushButton("Delete Job(s)", this);
mDeleteJobTextEdit = new QLineEdit(this);
mSubmitJobTextEdit = new QLineEdit("", this);
mTextEdit = new QTextEdit(this);
mTextEdit = new QTextEdit(this);
mOpenFileButton = new QPushButton("Open File", this);
mOpenFileEdit = new QLineEdit(this);
mOpenDirButton = new QPushButton("Open Directory", this);
mOpenDirEdit = new QLineEdit(this);
int row = 0;
layout->addWidget(proxyHostLabel, row, 0);
......@@ -82,8 +87,12 @@ ExamplePortalWidget::ExamplePortalWidget(QWidget *parent)
layout->addWidget(mGetAllJobInfoButton, ++row, 1);
layout->addWidget(mDeleteJobButton, ++row, 1);
layout->addWidget(mDeleteJobTextEdit, row, 2);
layout->addWidget(mTextEdit, ++row, 0, 2, 3);
row++;
layout->addWidget(mOpenFileButton, ++row, 1);
layout->addWidget(mOpenFileEdit, row, 2);
layout->addWidget(mOpenDirButton, ++row, 1);
layout->addWidget(mOpenDirEdit, row, 2);
connect(mConnectButton, &QPushButton::pressed, this,
&ExamplePortalWidget::connectToHost);
......@@ -114,40 +123,45 @@ ExamplePortalWidget::ExamplePortalWidget(QWidget *parent)
connect(mDeleteJobButton, &QPushButton::pressed, this,
&ExamplePortalWidget::submitDeleteJobToHost);
mSession = std::make_shared<SessionController>();
connect(mSession.get(), &SessionController::connectionFailed, this,
mSessionCon = std::make_shared<SessionController>();
connect(mSessionCon.get(), &SessionController::connectionFailed, this,
&ExamplePortalWidget::connectionFailed);
connect(mSession.get(), &SessionController::connectionSuccessful, this,
connect(mSessionCon.get(), &SessionController::connectionSuccessful, this,
&ExamplePortalWidget::connectionSuccessful);
connect(mSession.get(), &SessionController::disconnectSuccessful, this,
connect(mSessionCon.get(), &SessionController::disconnectSuccessful, this,
&ExamplePortalWidget::disconnectSuccessful);
connect(mSession.get(),
connect(mSessionCon.get(),
&SessionController::interactiveAuthenticationRequested, this,
&ExamplePortalWidget::interactiveAuthenticationRequested);
connect(mSession.get(), &SessionController::getServerPublicKeyFailed, this,
connect(mSessionCon.get(), &SessionController::getServerPublicKeyFailed, this,
&ExamplePortalWidget::getServerPublicKeyFailed);
connect(mSession.get(), &SessionController::hostUnknown, this,
connect(mSessionCon.get(), &SessionController::hostUnknown, this,
&ExamplePortalWidget::hostUnknown);
connect(mSession.get(), &SessionController::hostPublicKeyChanged, this,
connect(mSessionCon.get(), &SessionController::hostPublicKeyChanged, this,
&ExamplePortalWidget::hostPublicKeyChanged);
connect(mSession.get(), &SessionController::verifyKnownHostSuccessful, this,
&ExamplePortalWidget::verifyKnownHostSuccessful);
connect(mSession.get(), &SessionController::knownHostError, this,
connect(mSessionCon.get(), &SessionController::verifyKnownHostSuccessful,
this, &ExamplePortalWidget::verifyKnownHostSuccessful);
connect(mSessionCon.get(), &SessionController::knownHostError, this,
&ExamplePortalWidget::knownHostError);
connect(mSession.get(), &SessionController::authenticationError, this,
connect(mSessionCon.get(), &SessionController::authenticationError, this,
&ExamplePortalWidget::authenticationError);
connect(mSession.get(), &SessionController::authenticationSucceeded, this,
connect(mSessionCon.get(), &SessionController::authenticationSucceeded, this,
&ExamplePortalWidget::authenticationSucceeded);
connect(mSession.get(), &SessionController::passwordRequested, this,
connect(mSessionCon.get(), &SessionController::passwordRequested, this,
&ExamplePortalWidget::passwordRequested);
connect(mSession.get(), &SessionController::loginBannerIssued, this,
connect(mSessionCon.get(), &SessionController::loginBannerIssued, this,
&ExamplePortalWidget::loginBannerIssued);
connect(mSession.get(), &SessionController::execOutputReady, this,
connect(mSessionCon.get(), &SessionController::execOutputReady, this,
&ExamplePortalWidget::execOutputReady);
connect(mSession.get(), &SessionController::execFailed, this,
connect(mSessionCon.get(), &SessionController::execFailed, this,
&ExamplePortalWidget::execFailed);
connect(mSession.get(), &SessionController::execFinished, this,
connect(mSessionCon.get(), &SessionController::execFinished, this,
&ExamplePortalWidget::execFinished);
connect(mOpenFileButton, &QPushButton::pressed, this,
&ExamplePortalWidget::openFile);
connect(mOpenDirButton, &QPushButton::pressed, this,
&ExamplePortalWidget::openDir);
}
void ExamplePortalWidget::connectToHost()
......@@ -156,16 +170,16 @@ void ExamplePortalWidget::connectToHost()
if (mConnectButton->text().compare("Disconnect") == 0)
{
mSession->disconnect();