From 75bd59bf23ff00c5a89bc8527e08d9e3f58e8188 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Wed, 17 Jan 2018 10:17:34 +0100
Subject: [PATCH] GISASInstrumentItem removed from JobItem and JobItemUtils

---
 GUI/coregui/Models/JobItem.cpp           | 4 ++--
 GUI/coregui/Models/JobItem.h             | 5 +++--
 GUI/coregui/Models/JobItemUtils.cpp      | 8 ++++----
 GUI/coregui/Models/JobItemUtils.h        | 7 +++----
 GUI/coregui/Models/JobModelFunctions.cpp | 7 ++++++-
 5 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/GUI/coregui/Models/JobItem.cpp b/GUI/coregui/Models/JobItem.cpp
index 80b8dc48c7f..02341365b00 100644
--- a/GUI/coregui/Models/JobItem.cpp
+++ b/GUI/coregui/Models/JobItem.cpp
@@ -214,9 +214,9 @@ MultiLayerItem* JobItem::multiLayerItem()
     return dynamic_cast<MultiLayerItem*>(getItem(T_SAMPLE));
 }
 
-GISASInstrumentItem* JobItem::instrumentItem()
+InstrumentItem* JobItem::instrumentItem()
 {
-    return dynamic_cast<GISASInstrumentItem*>(getItem(T_INSTRUMENT));
+    return dynamic_cast<InstrumentItem*>(getItem(T_INSTRUMENT));
 }
 
 void JobItem::setResults(const Simulation* simulation)
diff --git a/GUI/coregui/Models/JobItem.h b/GUI/coregui/Models/JobItem.h
index 3af4db532af..927f40f0e57 100644
--- a/GUI/coregui/Models/JobItem.h
+++ b/GUI/coregui/Models/JobItem.h
@@ -16,10 +16,11 @@
 #define JOBITEM_H
 
 #include "SessionItem.h"
+
 class IntensityDataItem;
 class Simulation;
 class MultiLayerItem;
-class GISASInstrumentItem;
+class InstrumentItem;
 class SimulationOptionsItem;
 class FitSuiteItem;
 class ParameterContainerItem;
@@ -83,7 +84,7 @@ public:
 
     MultiLayerItem* multiLayerItem();
 
-    GISASInstrumentItem* instrumentItem();
+    InstrumentItem* instrumentItem();
 
     SimulationOptionsItem* simulationOptionsItem();
 
diff --git a/GUI/coregui/Models/JobItemUtils.cpp b/GUI/coregui/Models/JobItemUtils.cpp
index d0832f7e0c8..ce734737450 100644
--- a/GUI/coregui/Models/JobItemUtils.cpp
+++ b/GUI/coregui/Models/JobItemUtils.cpp
@@ -71,7 +71,7 @@ void JobItemUtils::setResults(IntensityDataItem* intensityItem, const Simulation
 //! InstrumentItem is used to get domain's detector map for given units.
 
 void JobItemUtils::updateDataAxes(IntensityDataItem* intensityItem,
-                                  const GISASInstrumentItem* instrumentItem)
+                                  const InstrumentItem* instrumentItem)
 {
     Q_ASSERT(intensityItem);
 
@@ -152,7 +152,7 @@ AxesUnits JobItemUtils::preferableGUIAxesUnits(AxesUnits default_units)
 //! Sets axes units suitable for given instrument.
 
 void JobItemUtils::setIntensityItemAxesUnits(IntensityDataItem* intensityItem,
-                                              const GISASInstrumentItem* instrumentItem)
+                                              const InstrumentItem* instrumentItem)
 {
     auto instrument = DomainObjectBuilder::buildInstrument(*instrumentItem);
     instrument->initDetector();
@@ -166,7 +166,7 @@ void JobItemUtils::setIntensityItemAxesUnits(IntensityDataItem* intensityItem,
 {
     ComboProperty combo;
 
-    foreach (auto units, detector->validAxesUnits())
+    for (auto units : detector->validAxesUnits())
         combo << nameFromAxesUnits(units);
 
     AxesUnits preferrable_units
@@ -212,7 +212,7 @@ void JobItemUtils::createDefaultDetectorMap(IntensityDataItem* intensityItem,
 }
 
 //! creates detector map from instrument description with axes corresponding to given units
-OutputData<double>* JobItemUtils::createDetectorMap(const GISASInstrumentItem* instrumentItem,
+OutputData<double>* JobItemUtils::createDetectorMap(const InstrumentItem* instrumentItem,
                                                      AxesUnits units)
 {
     auto instrument = DomainObjectBuilder::buildInstrument(*instrumentItem);
diff --git a/GUI/coregui/Models/JobItemUtils.h b/GUI/coregui/Models/JobItemUtils.h
index ef1d7c267ce..47964e28cdd 100644
--- a/GUI/coregui/Models/JobItemUtils.h
+++ b/GUI/coregui/Models/JobItemUtils.h
@@ -21,7 +21,6 @@
 class Simulation;
 class IntensityDataItem;
 class InstrumentItem;
-class GISASInstrumentItem;
 class JobItem;
 
 //! Contains set of convenience methods to set data to the IntensityDataItem from domain simulation.
@@ -35,7 +34,7 @@ BA_CORE_API_ void setResults(IntensityDataItem* intensityItem, const Simulation*
 
 //! updates axes of OutputData in IntensityData item
 BA_CORE_API_ void updateDataAxes(IntensityDataItem* intensityItem,
-                                 const GISASInstrumentItem* instrumentItem);
+                                 const InstrumentItem* instrumentItem);
 
 //! loads intensity data from project directory
 BA_CORE_API_ void loadIntensityData(IntensityDataItem* intensityItem, const QString& projectDir);
@@ -53,7 +52,7 @@ BA_CORE_API_ AxesUnits axesUnitsFromName(const QString& name);
 BA_CORE_API_ AxesUnits preferableGUIAxesUnits(AxesUnits default_units);
 
 BA_CORE_API_ void setIntensityItemAxesUnits(IntensityDataItem* intensityItem,
-                                            const GISASInstrumentItem* instrumentItem);
+                                            const InstrumentItem* instrumentItem);
 
 BA_CORE_API_ void setIntensityItemAxesUnits(IntensityDataItem* intensityItem,
                                             const IDetector* detector);
@@ -63,7 +62,7 @@ BA_CORE_API_ void updateAxesTitle(IntensityDataItem* intensityItem);
 BA_CORE_API_ void createDefaultDetectorMap(IntensityDataItem* intensityItem,
                                            const InstrumentItem* instrumentItem);
 
-BA_CORE_API_ OutputData<double>* createDetectorMap(const GISASInstrumentItem* instrumentItem,
+BA_CORE_API_ OutputData<double>* createDetectorMap(const InstrumentItem* instrumentItem,
                                                    AxesUnits units);
 }
 
diff --git a/GUI/coregui/Models/JobModelFunctions.cpp b/GUI/coregui/Models/JobModelFunctions.cpp
index bdf54a109eb..c3371c79245 100644
--- a/GUI/coregui/Models/JobModelFunctions.cpp
+++ b/GUI/coregui/Models/JobModelFunctions.cpp
@@ -96,7 +96,12 @@ void JobModelFunctions::processInstrumentLink(JobItem *jobItem)
 void JobModelFunctions::copyMasksToInstrument(JobItem *jobItem)
 {
     IntensityDataItem *intensityItem = jobItem->realDataItem()->intensityDataItem();
-    jobItem->instrumentItem()->importMasks(intensityItem->maskContainerItem());
+    if (auto instrument2DItem = dynamic_cast<Instrument2DItem*>(jobItem->instrumentItem())) {
+        instrument2DItem->importMasks(intensityItem->maskContainerItem());
+    } else {
+        throw GUIHelpers::Error("JobModelFunctions::copyMasksToInstrument() -> Error. Not "
+                                "implemented instrument type.");
+    }
 }
 
 //! Crops RealDataItem to the region of interest.
-- 
GitLab