diff --git a/Base/Type/OwningVector.h b/Base/Type/OwningVector.h index 8b056c7314069b47363d018d424501e71f291207..4d5590d1cd480097c8ceffa46d3257c4e05c515d 100644 --- a/Base/Type/OwningVector.h +++ b/Base/Type/OwningVector.h @@ -18,7 +18,6 @@ #ifndef BORNAGAIN_BASE_TYPE_OWNINGVECTOR_H #define BORNAGAIN_BASE_TYPE_OWNINGVECTOR_H -#include "Base/Util/Assert.h" #include <algorithm> #include <cstddef> #include <utility> @@ -50,8 +49,7 @@ public: void insert_at(size_t i, T* e) { m_v.insert(m_v.begin() + i, e); } void replace_at(size_t i, T* e) { - ASSERT(i < m_v.size()); - delete m_v[i]; + delete m_v.at(i); m_v[i] = e; } void delete_element(const T* e) diff --git a/GUI/Model/Data/DataItem.cpp b/GUI/Model/Data/DataItem.cpp index af3848c6e58b2398253117006fe27472387589dd..5dc0017f888bd8e7b9fe8da077af94a9e43fa2cf 100644 --- a/GUI/Model/Data/DataItem.cpp +++ b/GUI/Model/Data/DataItem.cpp @@ -26,7 +26,6 @@ namespace { namespace Tag { const QString FileName("FileName"); -const QString AxesUnits("AxesUnits"); // obsolete since 22.0 const QString XAxis("XAxis"); const QString YAxis("YAxis"); diff --git a/GUI/Model/FromCore/GUIExamplesFactory.cpp b/GUI/Model/FromCore/GUIExamplesFactory.cpp index 1cc4beef14db80c1d35c478400ab9cfb0dd44b54..8f232b7197ff89efac3615b4fc407e48b75f40d3 100644 --- a/GUI/Model/FromCore/GUIExamplesFactory.cpp +++ b/GUI/Model/FromCore/GUIExamplesFactory.cpp @@ -15,6 +15,7 @@ #include "GUI/Model/FromCore/GUIExamplesFactory.h" #include "Base/Util/Assert.h" #include "GUI/Model/FromCore/ItemizeSample.h" +#include "GUI/Model/Sample/SampleItem.h" #include "Sample/StandardSample/ExemplarySamples.h" #include <QMap> @@ -66,9 +67,13 @@ bool GUI::ExamplesFactory::isValidExampleName(const QString& name) SampleItem* GUI::ExamplesFactory::itemizeSample(const QString& name) { ASSERT(isValidExampleName(name)); - MultiLayer* sample = std::get<2>(builders[name])(); - - return GUI::FromCore::itemizeSample(*sample, name); + auto [title, description, builder] = builders[name]; + MultiLayer* sample = builder(); + ASSERT(sample); + SampleItem* result = GUI::FromCore::itemizeSample(*sample, name); + result->setName(title); + result->setDescription(description); + return result; } QStringList GUI::ExamplesFactory::exampleNames() diff --git a/GUI/Model/Job/BatchInfo.cpp b/GUI/Model/Job/BatchInfo.cpp index c36eba2be7e41f0fe2e0993cbc3fb6766f74baea..454e8d8b38767646174e156fc386e3000058326d 100644 --- a/GUI/Model/Job/BatchInfo.cpp +++ b/GUI/Model/Job/BatchInfo.cpp @@ -118,7 +118,6 @@ void BatchInfo::readFrom(QXmlStreamReader* r) else if (tag == Tag::Status) { QString s = XML::readTaggedString(r, tag); m_status = jobStatusFromString(s); - } else r->skipCurrentElement(); } diff --git a/GUI/Model/Job/JobsSet.cpp b/GUI/Model/Job/JobsSet.cpp index e09104ad127528d66fbe707cf385c6fdbb82350b..5626e371f54fa573dbed50c2325c7aea5691e2d3 100644 --- a/GUI/Model/Job/JobsSet.cpp +++ b/GUI/Model/Job/JobsSet.cpp @@ -40,7 +40,6 @@ void JobsSet::writeTo(QXmlStreamWriter* w) const { XML::writeAttribute(w, XML::Attrib::version, uint(1)); - // jobs for (const auto* job : *this) { w->writeStartElement(Tag::Job); XML::writeAttribute(w, XML::Attrib::name, job->batchInfo()->jobName()); @@ -65,7 +64,6 @@ void JobsSet::readFrom(QXmlStreamReader* r) } else if (tag == Tag::CurrentIndex) { size_t i = XML::readTaggedSize(r, tag); setCurrentIndex(i); - } else r->skipCurrentElement(); } @@ -151,27 +149,13 @@ bool JobsSet::hasUnfinishedJobs() const void JobsSet::runJob(JobItem* job_item) { if (job_item->thread()) - return; + throw std::runtime_error("Job already running"); connect(job_item, &JobItem::progressIncremented, this, &JobsSet::onProgressUpdate); connect(job_item, &JobItem::jobFinished, this, &JobsSet::onFinishedJob); - try { - job_item->initWorker(); - } catch (const std::exception& ex) { - QString message("JobsSet::runJob -> Error. " - "Attempt to create sample/instrument object from user description " - "has failed with following error message.\n\n"); - message += QString::fromStdString(std::string(ex.what())); - job_item->batchInfo()->setComments(message); - job_item->batchInfo()->setProgress(100); - job_item->setFailed(); - emit jobMeritsAttention(job_item); - return; - } - + job_item->initWorker(); auto* thread = job_item->thread(); - thread->start(); } @@ -197,12 +181,7 @@ void JobsSet::onProgressUpdate() nRunningJobs++; } - if (nRunningJobs) - global_progress /= nRunningJobs; - else - global_progress = -1; - - emit globalProgress(global_progress); + emit globalProgress(nRunningJobs ? global_progress / nRunningJobs : -1); } //! Cancels all running jobs. diff --git a/GUI/Model/Mask/MasksCatalog.cpp b/GUI/Model/Mask/MasksCatalog.cpp index 36b3d25d42b7a569f2f9b9eccbd7b330c009e846..9820e15bf09f6ad6b33e83d4f3e39d639f3469d1 100644 --- a/GUI/Model/Mask/MasksCatalog.cpp +++ b/GUI/Model/Mask/MasksCatalog.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "GUI/Model/Mask/MasksCatalog.h" +#include "Base/Util/Assert.h" #include "GUI/Model/Mask/MaskItems.h" MaskItem* MasksCatalog::create(Type type) diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp index dc1b57c791de8097993699c9daeaf6a875e49c76..2bcb3825079bb92c68774f8b93626e4efb4eb24d 100644 --- a/GUI/Model/Project/ProjectDocument.cpp +++ b/GUI/Model/Project/ProjectDocument.cpp @@ -71,7 +71,7 @@ void ProjectDocument::clear() m_samples->clear(); m_datafiles->clear(); m_options = std::make_unique<SimulationOptionsItem>(); - m_jobs = std::make_unique<JobsSet>(); + m_jobs->clear(); m_modified = false; } diff --git a/GUI/Model/Type/SetWithModel.cpp b/GUI/Model/Type/SetWithModel.cpp index dd0a69fa7065de6eca9e0c7849fe8f75b21bcc04..8ff83a6c9d282f6a8ddb48a8e4f2fe103eb163b1 100644 --- a/GUI/Model/Type/SetWithModel.cpp +++ b/GUI/Model/Type/SetWithModel.cpp @@ -14,8 +14,6 @@ #include "GUI/Model/Type/SetWithModel.h" -AbstractSetModel::AbstractSetModel(QObject* parent) - : QObject(parent) -{ -} +AbstractSetModel::AbstractSetModel() = default; + AbstractSetModel::~AbstractSetModel() = default; diff --git a/GUI/Model/Type/SetWithModel.h b/GUI/Model/Type/SetWithModel.h index 2e93979d981d412a502508a8cbcc3841e3926156..0186b3015be06631a24e61f161d634c0fd162c8e 100644 --- a/GUI/Model/Type/SetWithModel.h +++ b/GUI/Model/Type/SetWithModel.h @@ -33,7 +33,7 @@ class AbstractSetModel : public QObject { Q_OBJECT public: - explicit AbstractSetModel(QObject* parent = nullptr); + explicit AbstractSetModel(); virtual ~AbstractSetModel(); virtual void setCurrentIndex(size_t i) = 0; diff --git a/GUI/View/Device/AxisForm.cpp b/GUI/View/Device/AxisForm.cpp index f05d19ffc83ded571b615df727efe5d63908de5a..486e7096619816d663ce66ba83958eb992949ac2 100644 --- a/GUI/View/Device/AxisForm.cpp +++ b/GUI/View/Device/AxisForm.cpp @@ -18,47 +18,48 @@ #include "GUI/View/Numeric/DSpinBox.h" #include "GUI/View/Numeric/NumWidgetUtil.h" #include <QFormLayout> +#include <QSpinBox> -AxisForm::AxisForm(QWidget* parent, const QString& groupTitle, AxisProperty* axisProperty, - QString nbinsTooltip) - : StaticGroupBox(groupTitle, parent) - , m_axis_property(axisProperty) +AxisForm::AxisForm(QWidget* parent, const QString& group_title, AxisProperty* axis_property, + QString nbins_tooltip) + : StaticGroupBox(group_title, parent) { auto* layout = new QFormLayout; body()->setLayout(layout); layout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint); - m_nbins_spin_box = GUI::Util::createIntSpinBox([axisProperty] { return axisProperty->nbins(); }, - [this, axisProperty](int v) { - axisProperty->setNbins(v); - emit dataChanged(); - gDoc->setModified(); - }, - RealLimits::nonnegative(), nbinsTooltip); - layout->addRow("# bins:", m_nbins_spin_box); + QSpinBox* nbins_spin_box = + GUI::Util::createIntSpinBox([axis_property] { return axis_property->nbins(); }, + [this, axis_property](int v) { + axis_property->setNbins(v); + emit dataChanged(); + gDoc->setModified(); + }, + RealLimits::nonnegative(), nbins_tooltip); + layout->addRow("# bins:", nbins_spin_box); - m_min_spin_box = GUI::Util::addDoubleSpinBoxRow(layout, axisProperty->min()); - m_max_spin_box = GUI::Util::addDoubleSpinBoxRow(layout, axisProperty->max()); + DSpinBox* min_spin_box = GUI::Util::addDoubleSpinBoxRow(layout, axis_property->min()); + DSpinBox* max_spin_box = GUI::Util::addDoubleSpinBoxRow(layout, axis_property->max()); - connect(m_min_spin_box, &DSpinBox::valueChanged, [this](double v) { - if (m_axis_property->min().dVal() != v) { - m_axis_property->min().setDVal(v); + connect(min_spin_box, &DSpinBox::valueChanged, [this, axis_property, max_spin_box](double v) { + if (axis_property->min().dVal() != v) { + axis_property->min().setDVal(v); emit dataChanged(); - if (m_axis_property->max().dVal() < v) { - m_axis_property->max().setDVal(v); - m_max_spin_box->updateValue(); + if (axis_property->max().dVal() < v) { + axis_property->max().setDVal(v); + max_spin_box->updateValue(); } } }); - connect(m_max_spin_box, &DSpinBox::valueChanged, [this](double v) { - if (m_axis_property->max().dVal() != v) { - m_axis_property->max().setDVal(v); + connect(max_spin_box, &DSpinBox::valueChanged, [this, axis_property, min_spin_box](double v) { + if (axis_property->max().dVal() != v) { + axis_property->max().setDVal(v); emit dataChanged(); - if (m_axis_property->min().dVal() > v) { - m_axis_property->min().setDVal(v); - m_min_spin_box->updateValue(); + if (axis_property->min().dVal() > v) { + axis_property->min().setDVal(v); + min_spin_box->updateValue(); } } }); diff --git a/GUI/View/Device/AxisForm.h b/GUI/View/Device/AxisForm.h index c8b864c0987388c1d6ca5b93ee0b9dcf16453514..8da69a9c06000e09954ac83d7a0fa242e66adfa7 100644 --- a/GUI/View/Device/AxisForm.h +++ b/GUI/View/Device/AxisForm.h @@ -16,10 +16,8 @@ #define BORNAGAIN_GUI_VIEW_DEVICE_AXISFORM_H #include "GUI/View/Widget/GroupBoxes.h" -#include <QSpinBox> class AxisProperty; -class DSpinBox; //! Use this to edit an AxisProperty. //! @@ -29,17 +27,11 @@ class DSpinBox; class AxisForm : public StaticGroupBox { Q_OBJECT public: - AxisForm(QWidget* parent, const QString& groupTitle, AxisProperty* axisProperty, - QString nbinsTooltip = ""); + AxisForm(QWidget* parent, const QString& group_title, AxisProperty* axis_property, + QString nbins_tooltip = ""); signals: void dataChanged(); - -private: - QSpinBox* m_nbins_spin_box; - AxisProperty* m_axis_property; - DSpinBox* m_min_spin_box; - DSpinBox* m_max_spin_box; }; diff --git a/GUI/View/Job/JobsListing.cpp b/GUI/View/Job/JobsListing.cpp index 24aea95e9830e4bc0102de003718e726aec3db47..3733e497298fb9e5d5683f216e5f6acda8bdd83d 100644 --- a/GUI/View/Job/JobsListing.cpp +++ b/GUI/View/Job/JobsListing.cpp @@ -21,6 +21,7 @@ #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/View/Job/JobProgressDelegate.h" #include "GUI/View/Job/JobsQModel.h" +#include "GUI/View/Job/Simulate.h" #include "GUI/View/Setup/ActionFactory.h" #include "GUI/View/Widget/StyledToolbar.h" #include <QVBoxLayout> @@ -153,7 +154,8 @@ void JobsListing::onJobsDataChanged(const QModelIndex& topLeft, const QModelInde void JobsListing::onRun() { for (const QModelIndex& index : m_list_view->selectionModel()->selectedIndexes()) - m_model->launchJob(index); + if (!GUI::Sim::simulate(m_model->jobItemForIndex(index), gDoc->jobsRW())) + break; gDoc->setModified(); } diff --git a/GUI/View/Job/JobsQModel.cpp b/GUI/View/Job/JobsQModel.cpp index 43b4218872356980670a3190df1068fa19d947ae..f5bbb90fc38d4499863fa40e2ce0ccdee7a4bbf6 100644 --- a/GUI/View/Job/JobsQModel.cpp +++ b/GUI/View/Job/JobsQModel.cpp @@ -29,11 +29,7 @@ JobsQModel::JobsQModel(QObject* parent) onJobAdded(); } -JobsQModel::~JobsQModel() -{ - for (JobItem* job : *gDoc->jobsRW()) - disconnect(job, nullptr, this, nullptr); -} +JobsQModel::~JobsQModel() = default; int JobsQModel::rowCount(const QModelIndex&) const { @@ -67,16 +63,10 @@ QModelIndex JobsQModel::indexForJob(JobItem* job) return {}; } -void JobsQModel::launchJob(const QModelIndex& index) -{ - gDoc->jobsRW()->runJob(jobItemForIndex(index)); -} - void JobsQModel::removeJob(const QModelIndex& index) { beginRemoveRows(QModelIndex(), index.row(), index.row()); JobItem* job = jobItemForIndex(index); - disconnect(job, nullptr, this, nullptr); gDoc->jobsRW()->removeJob(job); endRemoveRows(); } diff --git a/GUI/View/Job/JobsQModel.h b/GUI/View/Job/JobsQModel.h index c513e88f83accbf42228837ca62b3eb12ef19e20..8d5047a7184dc9ad31b1c07fb05327628dc3d3ea 100644 --- a/GUI/View/Job/JobsQModel.h +++ b/GUI/View/Job/JobsQModel.h @@ -31,7 +31,6 @@ public: JobItem* jobItemForIndex(const QModelIndex& index) const; QModelIndex indexForJob(JobItem* job); - void launchJob(const QModelIndex& index); void removeJob(const QModelIndex& index); void cancelJob(const QModelIndex& index); diff --git a/GUI/View/Job/Simulate.cpp b/GUI/View/Job/Simulate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4b4e7d315a7d621f77ca3615f43447d3247f323a --- /dev/null +++ b/GUI/View/Job/Simulate.cpp @@ -0,0 +1,29 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/View/Job/Simulate.cpp +//! @brief Implements function GUI::Sim::simulate. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************************************ + +#include "GUI/View/Job/Simulate.h" +#include "GUI/Model/Job/JobItem.h" +#include "GUI/Model/Job/JobsSet.h" +#include "GUI/View/Info/MessageBox.h" + +bool GUI::Sim::simulate(JobItem* job_item, JobsSet* jobs) +{ + try { + jobs->runJob(job_item); + } catch (const std::exception& ex) { + GUI::Message::warning("BornAgain: job failed", ex.what()); + return false; + } + return true; +} diff --git a/GUI/View/Job/Simulate.h b/GUI/View/Job/Simulate.h new file mode 100644 index 0000000000000000000000000000000000000000..53d746f414713fdddcf1ca0a68599f21dcd48d6e --- /dev/null +++ b/GUI/View/Job/Simulate.h @@ -0,0 +1,28 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/View/Job/Simulate.h +//! @brief Defines function GUI::Sim::simulate. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************************************ + +#ifndef BORNAGAIN_GUI_VIEW_JOB_SIMULATE_H +#define BORNAGAIN_GUI_VIEW_JOB_SIMULATE_H + +class JobItem; +class JobsSet; + +namespace GUI::Sim { + +//! Runs job, pops up a warning box upon error, and returns true if no error occured. +bool simulate(JobItem*, JobsSet*); + +} // namespace GUI::Sim + +#endif // BORNAGAIN_GUI_VIEW_JOB_SIMULATE_H diff --git a/GUI/View/Overlay/IMaskOverlay.cpp b/GUI/View/Overlay/IMaskOverlay.cpp index 8fb870f4401bfb536683d430104e2624affdd47a..9f3ff23df79d295df2aa7da9f50887698d9e0a8c 100644 --- a/GUI/View/Overlay/IMaskOverlay.cpp +++ b/GUI/View/Overlay/IMaskOverlay.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "GUI/View/Overlay/IMaskOverlay.h" +#include "Base/Util/Assert.h" #include "GUI/Model/Mask/MaskItems.h" #include "GUI/View/Overlay/OverlayStyle.h" #include "GUI/View/Plotter/ColorMap.h" diff --git a/GUI/View/Overlay/PolygonOverlay.cpp b/GUI/View/Overlay/PolygonOverlay.cpp index d7da9a348e94c796743bd67fc3ec382982bcc696..0e97afd01fd0f78eeb29d690b518655d4b171ab4 100644 --- a/GUI/View/Overlay/PolygonOverlay.cpp +++ b/GUI/View/Overlay/PolygonOverlay.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "GUI/View/Overlay/PolygonOverlay.h" +#include "Base/Util/Assert.h" #include "GUI/Model/Mask/MaskItems.h" #include "GUI/Model/Mask/PointItem.h" #include "GUI/View/Overlay/OverlayStyle.h" diff --git a/GUI/View/Tuning/ParameterTuningWidget.cpp b/GUI/View/Tuning/ParameterTuningWidget.cpp index 3832462dbb0772569972fd7920475570b535eaa5..72337e1236aac82118a2cad4c50697a07a74f9f7 100644 --- a/GUI/View/Tuning/ParameterTuningWidget.cpp +++ b/GUI/View/Tuning/ParameterTuningWidget.cpp @@ -23,6 +23,7 @@ #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/View/Base/mainwindow_constants.h" #include "GUI/View/Info/CautionSign.h" +#include "GUI/View/Job/Simulate.h" #include "GUI/View/ParEdit/ParameterTuningDelegate.h" #include "GUI/View/Tuning/ParameterBackupWidget.h" #include "GUI/View/Tuning/PartunerQModel.h" @@ -163,7 +164,7 @@ void ParameterTuningWidget::onCurrentLinkChanged(ParameterItem* item) return; if (item) - m_jobs->runJob(m_job_item); + GUI::Sim::simulate(m_job_item, m_jobs); } void ParameterTuningWidget::onSliderRangeChanged(int value) @@ -224,7 +225,7 @@ void ParameterTuningWidget::restoreModelsOfCurrentJobItem(int index) closeActiveEditors(); m_jobs->restoreBackupPars(m_job_item, index); - m_jobs->runJob(m_job_item); + GUI::Sim::simulate(m_job_item, m_jobs); updateView(); gDoc->setModified(); } diff --git a/GUI/View/View/SampleView.cpp b/GUI/View/View/SampleView.cpp index e0542113974f37f93ee933ffe6ceaf76a1e20743..b63af3706e3e30a49fd4ee72dd70e983118632ef 100644 --- a/GUI/View/View/SampleView.cpp +++ b/GUI/View/View/SampleView.cpp @@ -22,6 +22,7 @@ #include "GUI/Model/Sample/SamplesSet.h" #include "GUI/View/Base/mainwindow_constants.h" #include "GUI/View/IO/PythonImport.h" +#include "GUI/View/Info/MessageBox.h" #include "GUI/View/Modelview/SetView.h" #include "GUI/View/Realspace/RealspacePanel.h" #include "GUI/View/Realspace/RealspaceWidget.h" @@ -75,8 +76,8 @@ SampleView::SampleView() hSplitter->addWidget(m_realspace_panel); - auto* scriptPanel = new ScriptPanel(this); - hSplitter->addWidget(scriptPanel); + auto* script_panel = new ScriptPanel(this); + hSplitter->addWidget(script_panel); applySplitterPos(); @@ -92,15 +93,15 @@ SampleView::SampleView() //... Finish - connect(gDoc->samples(), &SamplesSet::setChanged, [this, editor, scriptPanel] { + connect(gDoc->samples(), &SamplesSet::setChanged, [this, editor, script_panel] { SampleItem* t = gDoc->samplesRW()->currentItem(); editor->setCurrentSample(t); onRequestViewInRealspace(t); - scriptPanel->setCurrentSample(t); + script_panel->setCurrentSample(t); updateActions(); }); - connect(editor, &SampleEditor::modified, scriptPanel, &ScriptPanel::onSampleModified); + connect(editor, &SampleEditor::modified, script_panel, &ScriptPanel::onSampleModified); connect(editor, &SampleEditor::requestViewInRealspace, this, &SampleView::onRequestViewInRealspace); @@ -159,20 +160,12 @@ void SampleView::createActions(QToolBar* toolbar) choose_from_library_action->setToolTip("Choose from sample examples"); auto* import_menu = new QMenu(this); choose_from_library_action->setMenu(import_menu); - for (const auto& exampleName : GUI::ExamplesFactory::exampleNames()) { - QString title, description; - std::tie(title, description) = GUI::ExamplesFactory::exampleInfo(exampleName); + for (const auto& example_name : GUI::ExamplesFactory::exampleNames()) { + const auto [title, description] = GUI::ExamplesFactory::exampleInfo(example_name); auto icon = QIcon(":/images/sample_layers2.png"); auto* action = import_menu->addAction(icon, title); action->setToolTip(description); - connect(action, &QAction::triggered, [this, exampleName, title, description] { - SampleItem* t = GUI::ExamplesFactory::itemizeSample(exampleName); - if (!t) - return; - t->setName(title); - t->setDescription(description); - m_set->add_item(t); - }); + connect(action, &QAction::triggered, [this, example_name] { loadExample(example_name); }); } //... Copy and remove actions @@ -226,6 +219,17 @@ void SampleView::onRequestViewInRealspace(Item3D* item) m_realspace_panel->widget()->setDisplayedItem(gDoc->samplesRW()->currentItem(), item); } +void SampleView::loadExample(const QString& example_name) +{ + try { + SampleItem* t = GUI::ExamplesFactory::itemizeSample(example_name); + ASSERT(t); + m_set->add_item(t); + } catch (const std::exception& ex) { + GUI::Message::warning("Cannot load exemplary sample", ex.what()); + } +} + void SampleView::onAboutToRemoveItem(Item3D* item) { // If an item shall be deleted from the sample, check whether Realspace is affected. diff --git a/GUI/View/View/SampleView.h b/GUI/View/View/SampleView.h index 3490655fff98dce924217dcf03851eecc2958ac1..2e5466a334c0044d254fa9aa968eb79f37b98006 100644 --- a/GUI/View/View/SampleView.h +++ b/GUI/View/View/SampleView.h @@ -35,6 +35,7 @@ private: void updateActions(); void onRequestViewInRealspace(Item3D* item); + void loadExample(const QString& example_name); void onAboutToRemoveItem(Item3D* item); void applySplitterPos(); diff --git a/GUI/View/View/SimulationView.cpp b/GUI/View/View/SimulationView.cpp index 84a5860a97e2a2f5795c227339fe77a2cb7880f3..2a95fa44464d75b0da9f1504c243b7ae9f0e6e05 100644 --- a/GUI/View/View/SimulationView.cpp +++ b/GUI/View/View/SimulationView.cpp @@ -24,12 +24,14 @@ #include "GUI/Model/Sim/SimulationOptionsItem.h" #include "GUI/View/IO/PythonExport.h" #include "GUI/View/Info/MessageBox.h" +#include "GUI/View/Job/Simulate.h" #include "GUI/View/Widget/AppConfig.h" #include "GUI/View/Widget/GroupBoxes.h" #include <QButtonGroup> #include <QFormLayout> #include <QMessageBox> #include <QVBoxLayout> +#include <iostream> #include <thread> SimulationView::SimulationView() @@ -260,10 +262,17 @@ void SimulationView::simulate() } auto* job_item = new JobItem(gDoc->samples()->currentItem(), gDoc->instruments()->currentItem(), nullptr /*gDoc->datafiles()->currentItem()*/, optionsItem()); - JobsSet* jobs = gDoc->jobsRW(); - jobs->addJobItem(job_item); - jobs->runJob(job_item); + std::cout << "DEBUG 1 SimulationView::simulate() ji=" << job_item + << " #jobs=" << gDoc->jobs()->size() << std::endl; + gDoc->jobsRW()->addJobItem(job_item); + std::cout << "DEBUG 2 SimulationView::simulate() ji=" << job_item + << " #jobs=" << gDoc->jobs()->size() << std::endl; + GUI::Sim::simulate(job_item, gDoc->jobsRW()); + std::cout << "DEBUG 3 SimulationView::simulate() ji=" << job_item + << " #jobs=" << gDoc->jobs()->size() << std::endl; gDoc->setModified(); + std::cout << "DEBUG 4 SimulationView::simulate() ji=" << job_item + << " #jobs=" << gDoc->jobs()->size() << std::endl; } void SimulationView::exportPythonScript() diff --git a/Img3D/View/Canvas.cpp b/Img3D/View/Canvas.cpp index 74054e19492a9e45c8aed93c1fe67b23191284dd..cfc9a4a46ee10df2892e998f11eadf4b805c8dc9 100644 --- a/Img3D/View/Canvas.cpp +++ b/Img3D/View/Canvas.cpp @@ -85,9 +85,8 @@ void Canvas::setModel(Model* m) releaseBuffers(); m_model = m; switchCamera(true); - if (!m) + if (!m || !m_camera) return; - ASSERT(m_camera); m_camera->set(); } diff --git a/Resample/Particle/ReMesocrystal.cpp b/Resample/Particle/ReMesocrystal.cpp index 9a8bee3540a47c0ae78bb93bab3ff7e1cbf2f83a..c9535a2292992e717b4ff8e55628334d0401413b 100644 --- a/Resample/Particle/ReMesocrystal.cpp +++ b/Resample/Particle/ReMesocrystal.cpp @@ -16,6 +16,7 @@ #include "Base/Math/Numeric.h" #include "Base/Spin/SpinMatrix.h" #include "Base/Type/Span.h" +#include "Base/Util/Assert.h" #include "Base/Vector/WavevectorInfo.h" #include "Resample/Particle/ReParticle.h" #include <numbers>