From a6a40f34dca9fafc2d23426d209b14d710632233 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Fri, 1 Mar 2024 11:59:05 +0100
Subject: [PATCH] rm LinkInstrumentManager - missed nowhere??

---
 GUI/Model/Project/LinkInstrumentManager.cpp | 144 --------------------
 GUI/Model/Project/LinkInstrumentManager.h   |  51 -------
 GUI/Model/Project/ProjectDocument.cpp       |   3 -
 GUI/Model/Project/ProjectDocument.h         |   4 -
 4 files changed, 202 deletions(-)
 delete mode 100644 GUI/Model/Project/LinkInstrumentManager.cpp
 delete mode 100644 GUI/Model/Project/LinkInstrumentManager.h

diff --git a/GUI/Model/Project/LinkInstrumentManager.cpp b/GUI/Model/Project/LinkInstrumentManager.cpp
deleted file mode 100644
index eb2bb5deefb..00000000000
--- a/GUI/Model/Project/LinkInstrumentManager.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-//  ************************************************************************************************
-//
-//  BornAgain: simulate and fit reflection and scattering
-//
-//! @file      GUI/Model/Project/LinkInstrumentManager.cpp
-//! @brief     Implements class LinkInstrumentManager.
-//!
-//! @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/Model/Project/LinkInstrumentManager.h"
-#include "Base/Util/Assert.h"
-#include "GUI/Model/Device/DatafileItem.h"
-#include "GUI/Model/Device/InstrumentItems.h"
-#include "GUI/Model/Device/InstrumentsSet.h"
-#include "GUI/Model/Files/DatafilesSet.h"
-#include "GUI/Model/Project/ProjectDocument.h"
-#include <QMessageBox>
-#include <QPushButton>
-#include <iostream>
-
-namespace {
-
-bool QuestionOnInstrumentReshaping(const QString& message)
-{
-    QMessageBox msgBox;
-    msgBox.setText("Instrument description conflicts with the experimental data.");
-
-    QString informative;
-    informative.append(message);
-    informative.append("\n\nDo you want to adjust the instrument to the experimental data?\n\n");
-    msgBox.setInformativeText(informative);
-
-    QPushButton* modifyInstrumentButton =
-        msgBox.addButton("Yes, please modify instrument", QMessageBox::YesRole);
-    msgBox.addButton("No, leave as it is", QMessageBox::NoRole);
-
-    msgBox.exec();
-
-    return msgBox.clickedButton() == modifyInstrumentButton;
-}
-
-
-QString printShapeMessage(const std::vector<int>& instrument_shape,
-                          const std::vector<int>& data_shape)
-{
-    auto to_str = [](const std::vector<int>& shape) {
-        std::string result;
-        for (size_t i = 0, size = shape.size(); i < size; ++i) {
-            result += std::to_string(shape[i]);
-            if (i + 1 != size)
-                result += ", ";
-        }
-        return result;
-    };
-
-    std::string message_string = "instrument [";
-    message_string += to_str(instrument_shape);
-    message_string += "], data [";
-    message_string += to_str(data_shape);
-    message_string += "]";
-    return QString::fromStdString(message_string);
-}
-
-void warn(QWidget* parent, const QString& text)
-{
-    if (parent)
-        QMessageBox::warning(parent, "Cannot link to instrument", text);
-    else
-        std::cerr << text.toStdString() << std::endl;
-}
-
-} // namespace
-
-
-LinkInstrumentManager::LinkInstrumentManager(ProjectDocument* document)
-    : m_doc(document)
-{
-    connect(m_doc->instruments(), &InstrumentsSet::setChanged, this,
-            &LinkInstrumentManager::onInstrumentAddedOrRemoved);
-
-    connect(m_doc->instruments(), &InstrumentsSet::currentModified, this,
-            &LinkInstrumentManager::onInstrumentChanged);
-}
-
-bool LinkInstrumentManager::canLinkDataToInstrument(const DatafileItem* dfi,
-                                                    const QString& identifier,
-                                                    QWidget* parent) const
-{
-    auto* instrumentItem = m_doc->instruments()->findInstrumentItemById(identifier);
-
-    // linking to null instrument is possible, it means unlinking from currently linked
-    if (!instrumentItem)
-        return true;
-
-    if (instrumentItem->axdims().size() != dfi->axdims().size()) {
-        ::warn(parent, "Cannot link, data is incompatible with the instrument.");
-        return false;
-    }
-
-    if (instrumentItem->alignedWith(dfi))
-        return true;
-
-    ASSERT(parent);
-    QString message =
-        dfi->holdsDimensionalData()
-            ? "Experimental data carries information on the range/points of measurement."
-            : printShapeMessage(instrumentItem->axdims(), dfi->axdims());
-    if (!QuestionOnInstrumentReshaping(message))
-        return false;
-
-    instrumentItem->updateToRealData(dfi);
-    emit m_doc->instruments()->currentModified();
-    return true;
-}
-
-void LinkInstrumentManager::onInstrumentChanged()
-{
-    ASSERT(gDoc);
-    ASSERT(gDoc->instruments());
-    const InstrumentItem* instrument = gDoc->instruments()->currentItem();
-    // Run through all DatafileItem and refresh linking to match possible change in detector
-    // axes definition.
-    for (DatafileItem* dfi : *m_doc->datafilesModifier())
-        if (dfi->instrumentId() == instrument->id()) {
-            if (!instrument->alignedWith(dfi)) {
-                dfi->unlinkFromInstrument();
-                emit linkToInstrumentChanged(dfi);
-            } else
-                dfi->linkToInstrument(instrument); // link stays same, only data is updated
-        }
-}
-
-void LinkInstrumentManager::onInstrumentAddedOrRemoved()
-{
-    // remove links in realItems (in case of a linked instrument was removed)
-    for (DatafileItem* dfi : *m_doc->datafilesModifier())
-        if (!m_doc->instruments()->instrumentExists(dfi->instrumentId()))
-            dfi->unlinkFromInstrument();
-}
diff --git a/GUI/Model/Project/LinkInstrumentManager.h b/GUI/Model/Project/LinkInstrumentManager.h
deleted file mode 100644
index 14712808350..00000000000
--- a/GUI/Model/Project/LinkInstrumentManager.h
+++ /dev/null
@@ -1,51 +0,0 @@
-//  ************************************************************************************************
-//
-//  BornAgain: simulate and fit reflection and scattering
-//
-//! @file      GUI/Model/Project/LinkInstrumentManager.h
-//! @brief     Defines class LinkInstrumentManager.
-//!
-//! @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_MODEL_PROJECT_LINKINSTRUMENTMANAGER_H
-#define BORNAGAIN_GUI_MODEL_PROJECT_LINKINSTRUMENTMANAGER_H
-
-#include <QObject>
-
-class DatafileItem;
-class InstrumentItem;
-class ProjectDocument;
-
-//! The LinkInstrumentManager class provides communication between InstrumentsSet and
-//! DatafilesSet. Particularly, it notifies DatafileItem about changes in linked instruments
-//! to adjust axes of Data2DItem.
-
-class LinkInstrumentManager : public QObject {
-    Q_OBJECT
-public:
-    LinkInstrumentManager(ProjectDocument* document);
-
-    //! Returns true if DatafileItem can be linked to the instrument (same number of bins).
-    //! Also offers dialog to adjust instrument to match shape of real data.
-    //! quiet defines whether a "not possible" message box is shown if link is not possible. Use
-    //! this e.g. for unit tests. The question for adjusting the instrument is not suppressed by
-    //! this flag.
-    bool canLinkDataToInstrument(const DatafileItem* dfi, const QString& identifier,
-                                 QWidget* parent) const;
-
-signals:
-    void linkToInstrumentChanged(const DatafileItem* dfi);
-
-private:
-    void onInstrumentChanged();
-    void onInstrumentAddedOrRemoved();
-
-    ProjectDocument* m_doc;
-};
-
-#endif // BORNAGAIN_GUI_MODEL_PROJECT_LINKINSTRUMENTMANAGER_H
diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp
index ba531bac46d..18ce300b929 100644
--- a/GUI/Model/Project/ProjectDocument.cpp
+++ b/GUI/Model/Project/ProjectDocument.cpp
@@ -18,7 +18,6 @@
 #include "GUI/Model/Device/InstrumentsSet.h"
 #include "GUI/Model/Files/DatafilesSet.h"
 #include "GUI/Model/Material/MaterialItem.h"
-#include "GUI/Model/Project/LinkInstrumentManager.h"
 #include "GUI/Model/Project/ProjectUtil.h"
 #include "GUI/Model/Sample/ItemWithMaterial.h"
 #include "GUI/Model/Sample/SamplesSet.h"
@@ -55,7 +54,6 @@ const QString ActiveView("ActiveView");
 
 ProjectDocument::ProjectDocument()
     : m_modified(false)
-    , m_link_manager(std::unique_ptr<LinkInstrumentManager>())
     , m_options(std::make_unique<SimulationOptionsItem>())
     , m_instruments(std::make_unique<InstrumentsSet>())
     , m_samples(std::make_unique<SamplesSet>())
@@ -68,7 +66,6 @@ ProjectDocument::ProjectDocument()
     connect(m_instruments.get(), &InstrumentsSet::currentModified, this,
             &ProjectDocument::onModelChanged);
 
-    m_link_manager = std::make_unique<LinkInstrumentManager>(this);
     setObjectName("ProjectDocument");
 }
 
diff --git a/GUI/Model/Project/ProjectDocument.h b/GUI/Model/Project/ProjectDocument.h
index fa99bf6f38d..f39ef953dee 100644
--- a/GUI/Model/Project/ProjectDocument.h
+++ b/GUI/Model/Project/ProjectDocument.h
@@ -21,7 +21,6 @@
 class DatafilesSet;
 class InstrumentsSet;
 class JobsSet;
-class LinkInstrumentManager;
 class MessageService;
 class ProjectDocument;
 class QIODevice;
@@ -76,14 +75,12 @@ public:
     const DatafilesSet* datafiles() const { return m_datafiles.get(); };
     const JobsSet* jobs() const { return m_jobs.get(); };
     const SimulationOptionsItem* simulationOptionsItem() const { return m_options.get(); };
-    const LinkInstrumentManager* linkInstrumentManager() const { return m_link_manager.get(); };
 
     InstrumentsSet* instrumentsModifier() { return m_instruments.get(); };
     SamplesSet* samplesModifier() { return m_samples.get(); };
     DatafilesSet* datafilesModifier() { return m_datafiles.get(); };
     JobsSet* jobsModifier() { return m_jobs.get(); };
     SimulationOptionsItem* simulationOptionsItemModifier() { return m_options.get(); };
-    LinkInstrumentManager* linkInstrumentManagerModifier() { return m_link_manager.get(); };
 
 signals:
     void projectSaved();
@@ -99,7 +96,6 @@ private:
     QString m_project_name;
     bool m_modified;
     QString m_current_version;
-    std::unique_ptr<LinkInstrumentManager> m_link_manager;
     std::unique_ptr<SimulationOptionsItem> m_options;
     std::unique_ptr<InstrumentsSet> m_instruments;
     std::unique_ptr<SamplesSet> m_samples;
-- 
GitLab