Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project modification tracking #2329

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 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 @@ -283,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
4 changes: 4 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 @@ -107,5 +109,7 @@ class GroomTool : public QWidget {
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
16 changes: 16 additions & 0 deletions Studio/Optimize/OptimizeTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ OptimizeTool::OptimizeTool(Preferences& prefs, Telemetry& telemetry) : preferenc
connect(line_edit, &QLineEdit::textChanged, this, &OptimizeTool::update_run_button);
}

auto set_session_modified = [this]() {
if (!session_) {
return;
}
session_->set_modified(true);
};

auto line_edits = findChildren<QLineEdit*>();
for (auto line_edit : line_edits) {
connect(line_edit, &QLineEdit::textChanged, this, set_session_modified);
}
auto check_boxes = findChildren<QCheckBox*>();
for (auto check_box : check_boxes) {
connect(check_box, &QCheckBox::toggled, this, set_session_modified);
}

Style::apply_normal_button_style(ui_->restoreDefaults);
}

Expand Down
1 change: 1 addition & 0 deletions Studio/Visualization/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ void Viewer::handle_ffc_paint(double display_pos[2], double world_pos[3]) {
ffc.setPainted(true);
session_->trigger_ffc_changed();
}
session_->set_modified(true);
}

//-----------------------------------------------------------------------------
Expand Down
Loading