more image window tweaks

- add image windows to View menu
- add setting to replace old image view instead of creating a new one
- add setting to turn on/off box
- add setting to turn on/off axes
This commit is contained in:
Axel Kohlmeyer
2023-08-11 03:25:58 -04:00
parent 93e67c9388
commit 035620d252
7 changed files with 75 additions and 16 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(lammps-gui VERSION 1.1.5 LANGUAGES CXX) project(lammps-gui VERSION 1.1.6 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -58,12 +58,12 @@ ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QWidge
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
auto *zoomin = new QPushButton(QIcon(":/gtk-zoom-in.png"), "Zoom In"); auto *zoomin = new QPushButton(QIcon(":/gtk-zoom-in.png"), "");
auto *zoomout = new QPushButton(QIcon(":/gtk-zoom-out.png"),"Zoom Out"); auto *zoomout = new QPushButton(QIcon(":/gtk-zoom-out.png"), "");
auto *rotleft = new QPushButton(QIcon(":/object-rotate-left.png"), "Rotate Left"); auto *rotleft = new QPushButton(QIcon(":/object-rotate-left.png"), "");
auto *rotright = new QPushButton(QIcon(":/object-rotate-right.png"), "Rotate Right"); auto *rotright = new QPushButton(QIcon(":/object-rotate-right.png"), "");
auto *rotup = new QPushButton(QIcon(":/gtk-go-up.png"),"Rotate Up"); auto *rotup = new QPushButton(QIcon(":/gtk-go-up.png"), "");
auto *rotdown = new QPushButton(QIcon(":/gtk-go-down.png"),"Rotate Down"); auto *rotdown = new QPushButton(QIcon(":/gtk-go-down.png"), "");
auto *combo = new QComboBox; auto *combo = new QComboBox;
combo->setObjectName("group"); combo->setObjectName("group");
int ngroup = lammps->id_count("group"); int ngroup = lammps->id_count("group");
@ -148,14 +148,14 @@ void ImageViewer::do_rot_right()
void ImageViewer::do_rot_down() void ImageViewer::do_rot_down()
{ {
hrot -= 15; hrot -= 15;
if (hrot < -0) hrot += 180; if (hrot < 0) hrot += 360;
createImage(); createImage();
} }
void ImageViewer::do_rot_up() void ImageViewer::do_rot_up()
{ {
hrot += 15; hrot += 15;
if (hrot > 180) hrot -= 180; if (hrot > 360) hrot -= 360;
createImage(); createImage();
} }
@ -178,6 +178,7 @@ void ImageViewer::createImage()
int aa = settings.value("antialias", 0).toInt() + 1; int aa = settings.value("antialias", 0).toInt() + 1;
int xsize = settings.value("xsize", 800).toInt() * aa; int xsize = settings.value("xsize", 800).toInt() * aa;
int ysize = settings.value("ysize", 600).toInt() * aa; int ysize = settings.value("ysize", 600).toInt() * aa;
int hhrot = (hrot > 180) ? 360 - hrot : hrot;
dumpcmd += blank + settings.value("color", "type").toString(); dumpcmd += blank + settings.value("color", "type").toString();
dumpcmd += blank + settings.value("diameter", "type").toString(); dumpcmd += blank + settings.value("diameter", "type").toString();
@ -185,9 +186,18 @@ void ImageViewer::createImage()
dumpcmd += QString(" zoom ") + QString::number(zoom); dumpcmd += QString(" zoom ") + QString::number(zoom);
lammps->command(dumpcmd.toLocal8Bit()); lammps->command(dumpcmd.toLocal8Bit());
if (lammps->extract_setting("dimension") == 3) { if (lammps->extract_setting("dimension") == 3) {
dumpcmd += QString(" view ") + QString::number(hrot) + blank + QString::number(vrot); dumpcmd += QString(" view ") + QString::number(hhrot) + blank + QString::number(vrot);
} }
if (settings.value("ssao", false).toBool()) dumpcmd += QString(" ssao yes 453983 0.6"); if (settings.value("ssao", false).toBool()) dumpcmd += QString(" ssao yes 453983 0.6");
if (settings.value("box", true).toBool())
dumpcmd += QString(" box yes 0.02");
else
dumpcmd += QString(" box no 0.0");
if (settings.value("axes", true).toBool())
dumpcmd += QString(" axes yes 0.2 0.02");
else
dumpcmd += QString(" axes no 0.0 0.0");
settings.endGroup(); settings.endGroup();
lammps->command(dumpcmd.toLocal8Bit()); lammps->command(dumpcmd.toLocal8Bit());

View File

@ -53,9 +53,10 @@ private slots:
void do_rot_down(); void do_rot_down();
void change_group(int); void change_group(int);
public:
void createImage();
private: private:
void createActions(); void createActions();
void createImage();
void updateActions(); void updateActions();
void saveFile(const QString &fileName); void saveFile(const QString &fileName);
void scaleImage(double factor); void scaleImage(double factor);

View File

@ -177,7 +177,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
connect(ui->actionRedo, &QAction::triggered, this, &LammpsGui::redo); connect(ui->actionRedo, &QAction::triggered, this, &LammpsGui::redo);
connect(ui->actionRun_Buffer, &QAction::triggered, this, &LammpsGui::run_buffer); connect(ui->actionRun_Buffer, &QAction::triggered, this, &LammpsGui::run_buffer);
connect(ui->actionStop_LAMMPS, &QAction::triggered, this, &LammpsGui::stop_run); connect(ui->actionStop_LAMMPS, &QAction::triggered, this, &LammpsGui::stop_run);
connect(ui->actionImage, &QAction::triggered, this, &LammpsGui::view_image); connect(ui->actionImage, &QAction::triggered, this, &LammpsGui::render_image);
connect(ui->actionAbout_LAMMPS_GUI, &QAction::triggered, this, &LammpsGui::about); connect(ui->actionAbout_LAMMPS_GUI, &QAction::triggered, this, &LammpsGui::about);
connect(ui->action_Help, &QAction::triggered, this, &LammpsGui::help); connect(ui->action_Help, &QAction::triggered, this, &LammpsGui::help);
connect(ui->actionLAMMPS_Manual, &QAction::triggered, this, &LammpsGui::manual); connect(ui->actionLAMMPS_Manual, &QAction::triggered, this, &LammpsGui::manual);
@ -185,6 +185,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
connect(ui->actionDefaults, &QAction::triggered, this, &LammpsGui::defaults); connect(ui->actionDefaults, &QAction::triggered, this, &LammpsGui::defaults);
connect(ui->actionView_Log_Window, &QAction::triggered, this, &LammpsGui::view_log); connect(ui->actionView_Log_Window, &QAction::triggered, this, &LammpsGui::view_log);
connect(ui->actionView_Graph_Window, &QAction::triggered, this, &LammpsGui::view_chart); connect(ui->actionView_Graph_Window, &QAction::triggered, this, &LammpsGui::view_chart);
connect(ui->actionView_Image_Window, &QAction::triggered, this, &LammpsGui::view_image);
connect(ui->action_1, &QAction::triggered, this, &LammpsGui::open_recent); connect(ui->action_1, &QAction::triggered, this, &LammpsGui::open_recent);
connect(ui->action_2, &QAction::triggered, this, &LammpsGui::open_recent); connect(ui->action_2, &QAction::triggered, this, &LammpsGui::open_recent);
connect(ui->action_3, &QAction::triggered, this, &LammpsGui::open_recent); connect(ui->action_3, &QAction::triggered, this, &LammpsGui::open_recent);
@ -704,7 +705,7 @@ void LammpsGui::run_buffer()
logupdater->start(250); logupdater->start(250);
} }
void LammpsGui::view_image() void LammpsGui::render_image()
{ {
// LAMMPS is not re-entrant, so we can only query LAMMPS when it is not running // LAMMPS is not re-entrant, so we can only query LAMMPS when it is not running
if (!lammps.is_running()) { if (!lammps.is_running()) {
@ -714,6 +715,8 @@ void LammpsGui::view_image()
"Cannot create snapshot image without a system box"); "Cannot create snapshot image without a system box");
return; return;
} }
// if configured, delete old image window before opening new one
if (QSettings().value("imagereplace", false).toBool()) delete imagewindow;
imagewindow = new ImageViewer(current_file, &lammps); imagewindow = new ImageViewer(current_file, &lammps);
} else { } else {
QMessageBox::warning(this, "ImageViewer Error", QMessageBox::warning(this, "ImageViewer Error",
@ -756,6 +759,17 @@ void LammpsGui::view_log()
} }
} }
void LammpsGui::view_image()
{
if (imagewindow) {
if (imagewindow->isVisible()) {
imagewindow->hide();
} else {
imagewindow->show();
}
}
}
void LammpsGui::about() void LammpsGui::about()
{ {
std::string version = "This is LAMMPS-GUI version " LAMMPS_GUI_VERSION; std::string version = "This is LAMMPS-GUI version " LAMMPS_GUI_VERSION;
@ -871,6 +885,7 @@ void LammpsGui::preferences()
(oldecho != settings.value("echo", 0).toInt()) || (oldecho != settings.value("echo", 0).toInt()) ||
(oldcite != settings.value("cite", 0).toInt())) (oldcite != settings.value("cite", 0).toInt()))
lammps.close(); lammps.close();
if (imagewindow) imagewindow->createImage();
} }
} }

View File

@ -75,6 +75,7 @@ private slots:
void clear(); void clear();
void run_buffer(); void run_buffer();
void stop_run(); void stop_run();
void render_image();
void view_image(); void view_image();
void view_chart(); void view_chart();
void view_log(); void view_log();

View File

@ -86,6 +86,7 @@
</property> </property>
<addaction name="actionView_Log_Window"/> <addaction name="actionView_Log_Window"/>
<addaction name="actionView_Graph_Window"/> <addaction name="actionView_Graph_Window"/>
<addaction name="actionView_Image_Window"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
@ -404,6 +405,14 @@
<string>&amp;5.</string> <string>&amp;5.</string>
</property> </property>
</action> </action>
<action name="actionView_Image_Window">
<property name="icon">
<iconset theme="emblem-photos"/>
</property>
<property name="text">
<string>&amp;Image Window</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -120,6 +120,10 @@ void Preferences::accept()
if (combo) settings->setValue("antialias", combo->currentIndex()); if (combo) settings->setValue("antialias", combo->currentIndex());
QCheckBox *box = tabWidget->findChild<QCheckBox *>("ssao"); QCheckBox *box = tabWidget->findChild<QCheckBox *>("ssao");
if (box) settings->setValue("ssao", box->isChecked()); if (box) settings->setValue("ssao", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("box");
if (box) settings->setValue("box", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("axes");
if (box) settings->setValue("axes", box->isChecked());
settings->endGroup(); settings->endGroup();
// general settings // general settings
@ -131,6 +135,8 @@ void Preferences::accept()
if (box) settings->setValue("logreplace", box->isChecked()); if (box) settings->setValue("logreplace", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("chartreplace"); box = tabWidget->findChild<QCheckBox *>("chartreplace");
if (box) settings->setValue("chartreplace", box->isChecked()); if (box) settings->setValue("chartreplace", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("imagereplace");
if (box) settings->setValue("imagereplace", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("viewlog"); box = tabWidget->findChild<QCheckBox *>("viewlog");
if (box) settings->setValue("viewlog", box->isChecked()); if (box) settings->setValue("viewlog", box->isChecked());
box = tabWidget->findChild<QCheckBox *>("viewchart"); box = tabWidget->findChild<QCheckBox *>("viewchart");
@ -159,6 +165,10 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
logr->setObjectName("logreplace"); logr->setObjectName("logreplace");
logr->setCheckState(settings->value("logreplace", false).toBool() ? Qt::Checked logr->setCheckState(settings->value("logreplace", false).toBool() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
auto *imgr = new QCheckBox("Replace image window on new render");
imgr->setObjectName("imagereplace");
imgr->setCheckState(settings->value("imagereplace", false).toBool() ? Qt::Checked
: Qt::Unchecked);
auto *pltr = new QCheckBox("Replace chart window on new run"); auto *pltr = new QCheckBox("Replace chart window on new run");
pltr->setObjectName("chartreplace"); pltr->setObjectName("chartreplace");
pltr->setCheckState(settings->value("chartreplace", false).toBool() ? Qt::Checked pltr->setCheckState(settings->value("chartreplace", false).toBool() ? Qt::Checked
@ -202,6 +212,7 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
layout->addWidget(pltv); layout->addWidget(pltv);
layout->addWidget(logr); layout->addWidget(logr);
layout->addWidget(pltr); layout->addWidget(pltr);
layout->addWidget(imgr);
#if !defined(__APPLE__) #if !defined(__APPLE__)
layout->addLayout(tmplayout); layout->addLayout(tmplayout);
#endif #endif
@ -382,12 +393,16 @@ SnapshotTab::SnapshotTab(QSettings *_settings, QWidget *parent) :
auto *zoom = new QLabel("Zoom factor:"); auto *zoom = new QLabel("Zoom factor:");
auto *anti = new QLabel("Antialias:"); auto *anti = new QLabel("Antialias:");
auto *ssao = new QLabel("HQ Image mode:"); auto *ssao = new QLabel("HQ Image mode:");
auto *bbox = new QLabel("Show Box:");
auto *axes = new QLabel("Show Axes:");
settings->beginGroup("snapshot"); settings->beginGroup("snapshot");
auto *xval = new QLineEdit(settings->value("xsize", "800").toString()); auto *xval = new QLineEdit(settings->value("xsize", "800").toString());
auto *yval = new QLineEdit(settings->value("ysize", "600").toString()); auto *yval = new QLineEdit(settings->value("ysize", "600").toString());
auto *zval = new QLineEdit(settings->value("zoom", "1.0").toString()); auto *zval = new QLineEdit(settings->value("zoom", "1.0").toString());
auto *aval = new QComboBox; auto *aval = new QComboBox;
auto *sval = new QCheckBox; auto *sval = new QCheckBox;
auto *bval = new QCheckBox;
auto *eval = new QCheckBox;
sval->setCheckState(settings->value("ssao", false).toBool() ? Qt::Checked : Qt::Unchecked); sval->setCheckState(settings->value("ssao", false).toBool() ? Qt::Checked : Qt::Unchecked);
sval->setObjectName("ssao"); sval->setObjectName("ssao");
aval->addItem("1x", 1); aval->addItem("1x", 1);
@ -396,6 +411,10 @@ SnapshotTab::SnapshotTab(QSettings *_settings, QWidget *parent) :
aval->addItem("4x", 4); aval->addItem("4x", 4);
aval->setCurrentIndex(settings->value("antialias", "0").toInt()); aval->setCurrentIndex(settings->value("antialias", "0").toInt());
aval->setObjectName("anti"); aval->setObjectName("anti");
bval->setCheckState(settings->value("box", true).toBool() ? Qt::Checked : Qt::Unchecked);
bval->setObjectName("box");
eval->setCheckState(settings->value("axes", false).toBool() ? Qt::Checked : Qt::Unchecked);
eval->setObjectName("axes");
settings->endGroup(); settings->endGroup();
auto *intval = new QIntValidator(100, 100000, this); auto *intval = new QIntValidator(100, 100000, this);
@ -411,14 +430,18 @@ SnapshotTab::SnapshotTab(QSettings *_settings, QWidget *parent) :
grid->addWidget(zoom, 2, 0, Qt::AlignTop); grid->addWidget(zoom, 2, 0, Qt::AlignTop);
grid->addWidget(anti, 3, 0, Qt::AlignTop); grid->addWidget(anti, 3, 0, Qt::AlignTop);
grid->addWidget(ssao, 4, 0, Qt::AlignTop); grid->addWidget(ssao, 4, 0, Qt::AlignTop);
grid->addWidget(bbox, 5, 0, Qt::AlignTop);
grid->addWidget(axes, 6, 0, Qt::AlignTop);
grid->addWidget(xval, 0, 1, Qt::AlignTop); grid->addWidget(xval, 0, 1, Qt::AlignTop);
grid->addWidget(yval, 1, 1, Qt::AlignTop); grid->addWidget(yval, 1, 1, Qt::AlignTop);
grid->addWidget(zval, 2, 1, Qt::AlignTop); grid->addWidget(zval, 2, 1, Qt::AlignTop);
grid->addWidget(aval, 3, 1, Qt::AlignTop); grid->addWidget(aval, 3, 1, Qt::AlignTop);
grid->addWidget(sval, 4, 1, Qt::AlignVCenter); grid->addWidget(sval, 4, 1, Qt::AlignVCenter);
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Minimum, QSizePolicy::Expanding), 5, 0); grid->addWidget(bval, 5, 1, Qt::AlignVCenter);
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Minimum, QSizePolicy::Expanding), 5, 1); grid->addWidget(eval, 6, 1, Qt::AlignVCenter);
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding), 5, 2); grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Minimum, QSizePolicy::Expanding), 7, 0);
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Minimum, QSizePolicy::Expanding), 7, 1);
grid->addItem(new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding), 7, 2);
setLayout(grid); setLayout(grid);
} }