Skip to content

Commit

Permalink
Merge branch 'master' into 2326-java-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akenmorris authored Sep 20, 2024
2 parents 954a745 + 6fed0eb commit a22b12a
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 28 deletions.
3 changes: 3 additions & 0 deletions Studio/Data/DataTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ DataTool::DataTool(Preferences& prefs) : preferences_(prefs) {
connect(ui_->delete_plane_, &QPushButton::clicked, this, &DataTool::delete_planes_clicked);
connect(ui_->delete_ffc_, &QPushButton::clicked, this, &DataTool::delete_ffc_clicked);

connect(ui_->notes, &QTextEdit::textChanged, this, [this] { session_->set_modified(true); });

ui_->table_label->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_->landmarks_label->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_->constraints_label->setAttribute(Qt::WA_TransparentForMouseEvents);
Expand Down Expand Up @@ -624,6 +626,7 @@ void DataTool::subject_notes_changed() {
shape->get_subject()->set_notes(new_notes);
// update the table
update_table(false);
session_->set_modified(true);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Studio/Data/LandmarkTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ void LandmarkTableModel::set_session(QSharedPointer<Session> session) {
}

//---------------------------------------------------------------------------
void LandmarkTableModel::store_landmarks() { this->project_->set_landmarks(active_domain_, landmarks_); }
void LandmarkTableModel::store_landmarks() {
project_->set_landmarks(active_domain_, landmarks_);
session_->set_modified(true);
}

//---------------------------------------------------------------------------
void LandmarkTableModel::set_active_domain(int domain) { active_domain_ = domain; }

//---------------------------------------------------------------------------
void LandmarkTableModel::new_landmark() {
project_->new_landmark(active_domain_);
session_->set_modified(true);
update_table();
}

Expand Down
6 changes: 0 additions & 6 deletions Studio/Data/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ bool Preferences::get_center_checked() { return settings_.value("Studio/center_c
//-----------------------------------------------------------------------------
void Preferences::set_center_checked(bool value) { settings_.setValue("Studio/center_checked", value); }

//-----------------------------------------------------------------------------
bool Preferences::not_saved() { return !saved_; }

//-----------------------------------------------------------------------------
void Preferences::set_saved(bool saved) { saved_ = saved; }

//-----------------------------------------------------------------------------
QStringList Preferences::get_recent_files() {
update_recent_files();
Expand Down
4 changes: 0 additions & 4 deletions Studio/Data/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class Preferences : public QObject {
QStringList get_recent_files();
QStringList get_recent_paths();

bool not_saved();
void set_saved(bool saved = true);

QByteArray get_window_geometry();
void set_window_geometry(QByteArray geometry);

Expand Down Expand Up @@ -146,5 +143,4 @@ class Preferences : public QObject {
QStringList recent_paths_;

QSettings settings_;
bool saved_ = true;
};
21 changes: 20 additions & 1 deletion Studio/Data/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool Session::save_project(QString filename) {

set_project_path(QFileInfo(filename).absolutePath());

preferences_.set_saved();
modified_ = false;

progress.setValue(5);
QApplication::processEvents();
Expand Down Expand Up @@ -188,6 +188,8 @@ bool Session::save_project(QString filename) {

//---------------------------------------------------------------------------
bool Session::load_project(QString filename) {
modified_ = false;

if (!QFile::exists(filename)) {
QMessageBox::critical(nullptr, "ShapeWorksStudio", "File does not exist: " + filename, QMessageBox::Ok);
return false;
Expand Down Expand Up @@ -843,6 +845,10 @@ QString Session::get_display_name() {
name = name + " (read-only)";
}

if (modified_) {
name = name + "*";
}

return name;
}

Expand Down Expand Up @@ -947,6 +953,7 @@ void Session::set_feature_range_max(double value) {
//---------------------------------------------------------------------------
void Session::set_feature_uniform_scale(bool value) {
if (!is_loading()) {
set_modified(true);
params_.set("feature_uniform_scale", value);
Q_EMIT feature_range_changed();
}
Expand All @@ -963,8 +970,10 @@ void Session::handle_ctrl_click(PickResult result) {

if (landmarks_active_) {
new_landmark(result);
set_modified(true);
} else if (planes_active_) {
new_plane_point(result);
set_modified(true);
}
}

Expand Down Expand Up @@ -1325,6 +1334,16 @@ Eigen::MatrixXd Session::get_all_scalars(std::string target_feature) {
return all_scalars;
}

//---------------------------------------------------------------------------
void Session::set_modified(bool modified) {
if (modified == modified_) {
return;
}
SW_LOG("Project has been modified: {}", modified);
modified_ = modified;
Q_EMIT session_title_changed();
}

//---------------------------------------------------------------------------
void Session::set_ffc_paint_active(bool enabled) {
ffc_painting_active_ = enabled;
Expand Down
7 changes: 7 additions & 0 deletions Studio/Data/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Analyze/Analyze.h>
#include <Analyze/Particles.h>
#include <Data/Preferences.h>
#include <Logging.h>
#include <MeshManager.h>
#include <Particles/ParticleSystemEvaluation.h>
#include <Project/Project.h>
Expand Down Expand Up @@ -276,6 +277,9 @@ class Session : public QObject, public QEnableSharedFromThis<Session> {
void set_current_alignment(AlignmentType alignment) { current_alignment_ = alignment; }
AlignmentType get_current_alignment() { return current_alignment_; }

bool is_modified() { return modified_; }
void set_modified(bool modified);

public Q_SLOTS:
void set_feature_auto_scale(bool value);

Expand Down Expand Up @@ -306,6 +310,7 @@ class Session : public QObject, public QEnableSharedFromThis<Session> {
void reinsert_shapes();
void annotations_changed();
void save();
void session_title_changed();

public:
// constants
Expand Down Expand Up @@ -367,6 +372,8 @@ class Session : public QObject, public QEnableSharedFromThis<Session> {
QSharedPointer<PythonWorker> py_worker_;

AlignmentType current_alignment_{AlignmentType::Local};

bool modified_{false};
};

} // namespace shapeworks
35 changes: 35 additions & 0 deletions Studio/Groom/GroomTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ GroomTool::GroomTool(Preferences& prefs, Telemetry& telemetry) : preferences_(pr
ui_->sinc_iterations->setValidator(zero_and_up);
ui_->sinc_passband->setValidator(double_validator);

auto line_edits = findChildren<QLineEdit*>();
for (auto line_edit : line_edits) {
connect(line_edit, &QLineEdit::textChanged, this, &GroomTool::set_session_modified);
}
auto spin_boxes = findChildren<QSpinBox*>();
for (auto spin_box : spin_boxes) {
connect(spin_box, qOverload<int>(&QSpinBox::valueChanged), this, &GroomTool::set_session_modified);
}
auto double_spin_boxes = findChildren<QDoubleSpinBox*>();
for (auto double_spin_box : double_spin_boxes) {
connect(double_spin_box, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &GroomTool::set_session_modified);
}
auto check_boxes = findChildren<QCheckBox*>();
for (auto check_box : check_boxes) {
connect(check_box, &QCheckBox::toggled, this, &GroomTool::set_session_modified);
}
auto combo_boxes = findChildren<QComboBox*>();
for (auto combo_box : combo_boxes) {
connect(combo_box, qOverload<int>(&QComboBox::currentIndexChanged), this, &GroomTool::set_session_modified);
}

update_ui();
}

Expand Down Expand Up @@ -194,6 +215,7 @@ void GroomTool::update_page() {

//---------------------------------------------------------------------------
void GroomTool::update_domain_box() {
block_signals_ = true;
auto domain_names = session_->get_project()->get_domain_names();
ui_->domain_panel->setVisible(domain_names.size() > 1);

Expand All @@ -218,6 +240,7 @@ void GroomTool::update_domain_box() {
ui_->shared_boundary_second_domain->setCurrentIndex(ui_->shared_boundary_second_domain->currentIndex() + 1);
}
}
block_signals_ = false;
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -281,6 +304,13 @@ void GroomTool::update_reflect_choices() {
}
}

//---------------------------------------------------------------------------
void GroomTool::set_session_modified() {
if (session_) {
session_->set_modified(true);
}
}

//---------------------------------------------------------------------------
void GroomTool::load_params() {
auto params = GroomParameters(session_->get_project(), current_domain_);
Expand Down Expand Up @@ -709,6 +739,10 @@ void GroomTool::shutdown_threads() {

//---------------------------------------------------------------------------
void GroomTool::domain_changed() {
if (block_signals_) {
return;
}

if (current_domain_ != "") {
store_params();
}
Expand All @@ -719,6 +753,7 @@ void GroomTool::domain_changed() {
current_domain_ = ui_->domain_box->currentText().toStdString();
}

std::cerr << "calling load_params3\n";
load_params();

/*
Expand Down
6 changes: 6 additions & 0 deletions Studio/Groom/GroomTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class GroomTool : public QWidget {
void update_reflect_columns();
void update_reflect_choices();

void set_session_modified();

Preferences& preferences_;
Telemetry& telemetry_;

Expand All @@ -105,5 +107,9 @@ class GroomTool : public QWidget {
std::string current_domain_;

QStringList reflect_columns_;

bool block_signals_ = false;

bool block_session_modify_ = false;
};
} // namespace shapeworks
37 changes: 21 additions & 16 deletions Studio/Interface/ShapeWorksStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ ShapeWorksStudioApp::ShapeWorksStudioApp() {
connect(ui_->glyphs_visible_button, &QPushButton::clicked, this, &ShapeWorksStudioApp::handle_glyph_changed);
connect(ui_->surface_visible_button, &QPushButton::clicked, this, &ShapeWorksStudioApp::handle_glyph_changed);

preferences_.set_saved();
enable_possible_actions();

connect(ui_->actionAbout, &QAction::triggered, this, &ShapeWorksStudioApp::about);
Expand Down Expand Up @@ -253,11 +252,11 @@ void ShapeWorksStudioApp::initialize_vtk() { lightbox_->set_render_window(ui_->q

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::on_action_new_project_triggered() {
if (preferences_.not_saved() && ui_->action_save_project->isEnabled()) {
bool needs_save = session_ ? session_->is_modified() : false;
if (needs_save && ui_->action_save_project->isEnabled()) {
// save the size of the window to preferences
QMessageBox msgBox;
msgBox.setText("Do you want to save your changes as a project file?");
msgBox.setInformativeText("This will reload generated files and changed settings.");
msgBox.setText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
Expand Down Expand Up @@ -874,6 +873,15 @@ void ShapeWorksStudioApp::create_compare_submenu() {
ui_->compare->setMenu(menu);
}

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::update_window_title() {
if (!session_) {
return;
}

setWindowTitle(session_->get_display_name());
}

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::handle_new_mesh() {
visualizer_->handle_new_mesh();
Expand Down Expand Up @@ -961,7 +969,7 @@ void ShapeWorksStudioApp::new_session() {
session_ = QSharedPointer<Session>::create(this, preferences_);
session_->set_parent(this);
session_->set_py_worker(get_py_worker());
setWindowTitle(session_->get_display_name());
update_window_title();

connect(session_->get_mesh_manager().get(), &MeshManager::progress, this, &ShapeWorksStudioApp::handle_progress);
connect(session_->get_mesh_manager().get(), &MeshManager::status, this, &ShapeWorksStudioApp::handle_status);
Expand All @@ -976,6 +984,7 @@ void ShapeWorksStudioApp::new_session() {
connect(session_.data(), &Session::reinsert_shapes, this, [&]() { update_display(true); });
connect(session_.data(), &Session::save, this, &ShapeWorksStudioApp::on_action_save_project_triggered);
connect(session_.data(), &Session::tool_state_changed, this, &ShapeWorksStudioApp::update_tool_mode);
connect(session_.data(), &Session::session_title_changed, this, &ShapeWorksStudioApp::update_window_title);

connect(ui_->feature_auto_scale, &QCheckBox::toggled, this, &ShapeWorksStudioApp::update_feature_map_scale);
connect(ui_->feature_auto_scale, &QCheckBox::toggled, session_.data(), &Session::set_feature_auto_scale);
Expand Down Expand Up @@ -1020,12 +1029,12 @@ void ShapeWorksStudioApp::new_session() {
ui_->action_analysis_mode->setChecked(false);
ui_->stacked_widget->setCurrentWidget(data_tool_.data());
ui_->controlsDock->setWindowTitle("Data");
preferences_.set_saved();
enable_possible_actions();
update_display(true);
visualizer_->update_viewer_properties();

ui_->view_mode_combobox->setCurrentIndex(DisplayMode::Original);
session_->set_modified(false);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -1484,12 +1493,7 @@ void ShapeWorksStudioApp::open_project(QString filename) {

update_tool_mode();

// set the zoom state
// ui_->thumbnail_size_slider->setValue(
// preferences_.get_preference("zoom_state", 1));

visualizer_->update_lut();
preferences_.set_saved();
enable_possible_actions();
visualizer_->reset_camera();

Expand Down Expand Up @@ -1532,7 +1536,7 @@ void ShapeWorksStudioApp::open_project(QString filename) {

session_->update_auto_glyph_size();

setWindowTitle(session_->get_display_name());
update_window_title();

// final check after loading that the view mode isn't set to something invalid
if (!is_view_combo_item_enabled(ui_->view_mode_combobox->currentIndex())) {
Expand All @@ -1546,6 +1550,7 @@ void ShapeWorksStudioApp::open_project(QString filename) {
handle_glyph_changed();
update_display(true);
handle_progress(100);
session_->set_modified(false);
SW_LOG("Project loaded: " + filename.toStdString());
}

Expand Down Expand Up @@ -1777,10 +1782,10 @@ void ShapeWorksStudioApp::action_export_screenshot_triggered() {
void ShapeWorksStudioApp::closeEvent(QCloseEvent* event) {
// close the preferences window in case it is open
preferences_window_->close();
if (preferences_.not_saved() && ui_->action_save_project->isEnabled()) {
bool needs_save = session_ ? session_->is_modified() : false;
if (needs_save && ui_->action_save_project->isEnabled()) {
QMessageBox msgBox;
msgBox.setText("Do you want to save your changes as a project file?");
msgBox.setInformativeText("This will reload generated files and changed settings.");
msgBox.setText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
Expand Down Expand Up @@ -1859,7 +1864,7 @@ void ShapeWorksStudioApp::save_project(QString filename) {
}

update_table();
setWindowTitle(session_->get_display_name());
update_window_title();
}

//---------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions Studio/Interface/ShapeWorksStudioApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ class ShapeWorksStudioApp : public QMainWindow {
void create_iso_submenu();
void create_compare_submenu();

void update_window_title();

/// designer form
Ui_ShapeWorksStudioApp* ui_;

Expand Down
Loading

0 comments on commit a22b12a

Please sign in to comment.