From cadb7d61bed2598a29a161fef8a1987880a320c3 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Thu, 9 Mar 2017 14:44:27 +0100
Subject: [PATCH] New abstract DetectorItem base class introduced.

---
 GUI/coregui/Models/ApplicationModels.cpp   |  2 +-
 GUI/coregui/Models/DetectorItems.cpp       | 11 ++++++++++-
 GUI/coregui/Models/DetectorItems.h         | 11 +++++++++++
 GUI/coregui/Models/DomainObjectBuilder.cpp |  2 +-
 GUI/coregui/Models/GUIObjectBuilder.cpp    |  2 +-
 GUI/coregui/Models/InstrumentItem.cpp      |  4 ++--
 GUI/coregui/Models/ItemFactory.cpp         |  4 ++--
 GUI/coregui/Models/ModelPath.cpp           |  2 +-
 GUI/coregui/Models/item_constants.h        |  2 +-
 GUI/coregui/Views/InstrumentView.cpp       |  2 +-
 Tests/UnitTests/GUI/TestMapperCases.h      |  4 ++--
 Tests/UnitTests/GUI/TestSessionModel.h     | 10 +++++-----
 12 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/GUI/coregui/Models/ApplicationModels.cpp b/GUI/coregui/Models/ApplicationModels.cpp
index 7505a3213a6..3db64af602d 100644
--- a/GUI/coregui/Models/ApplicationModels.cpp
+++ b/GUI/coregui/Models/ApplicationModels.cpp
@@ -118,7 +118,7 @@ void ApplicationModels::resetModels()
     m_instrumentModel->clear();
     SessionItem *instrument = m_instrumentModel->insertNewItem(Constants::InstrumentType);
     instrument->setItemName("Default GISAS");
-    m_instrumentModel->insertNewItem(Constants::DetectorType, m_instrumentModel->indexOfItem(instrument));
+    m_instrumentModel->insertNewItem(Constants::DetectorContainerType, m_instrumentModel->indexOfItem(instrument));
     m_instrumentModel->insertNewItem(Constants::BeamType, m_instrumentModel->indexOfItem(instrument));
 
 //    m_realDataModel->insertNewItem(Constants::RealDataType);
diff --git a/GUI/coregui/Models/DetectorItems.cpp b/GUI/coregui/Models/DetectorItems.cpp
index fabcf480910..b89e8f4bc5c 100644
--- a/GUI/coregui/Models/DetectorItems.cpp
+++ b/GUI/coregui/Models/DetectorItems.cpp
@@ -21,7 +21,7 @@ const QString DetectorContainerItem::P_DETECTOR = "DetectorType";
 const QString DetectorContainerItem::T_MASKS = "Mask tag";
 
 DetectorContainerItem::DetectorContainerItem()
-    : SessionItem(Constants::DetectorType)
+    : SessionItem(Constants::DetectorContainerType)
 {
     addGroupProperty(P_DETECTOR, Constants::DetectorGroup);
     registerTag(T_MASKS, 0, -1, QStringList() << Constants::MaskContainerType);
@@ -51,3 +51,12 @@ MaskContainerItem *DetectorContainerItem::maskContainerItem() const
     return 0;
 }
 
+// --------------------------------------------------------------------------------------------- //
+
+const QString DetectorItem::T_MASKS = "Masks";
+
+DetectorItem::DetectorItem(const QString& modelType)
+    : SessionItem(modelType)
+{
+    registerTag(T_MASKS, 0, -1, QStringList() << Constants::MaskContainerType);
+}
diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h
index 1a978cfe808..979d23b1a0d 100644
--- a/GUI/coregui/Models/DetectorItems.h
+++ b/GUI/coregui/Models/DetectorItems.h
@@ -34,4 +34,15 @@ public:
     MaskContainerItem *maskContainerItem() const;
 };
 
+class BA_CORE_API_ DetectorItem : public SessionItem
+{
+public:
+    static const QString T_MASKS;
+    explicit DetectorItem(const QString& modelType);
+
+    virtual std::unique_ptr<IDetector2D> createDetector() const = 0;
+    virtual std::unique_ptr<IResolutionFunction2D> createResolutionFunction() = 0;
+};
+
+
 #endif // DETECTORITEMS_H
diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp
index 0d26a354cb7..969a5b291c7 100644
--- a/GUI/coregui/Models/DomainObjectBuilder.cpp
+++ b/GUI/coregui/Models/DomainObjectBuilder.cpp
@@ -135,7 +135,7 @@ std::unique_ptr<Instrument> DomainObjectBuilder::buildInstrument(
             if (P_beam) {
                 P_instrument->setBeam(*P_beam);
             }
-        } else if (children[i]->modelType() == Constants::DetectorType) {
+        } else if (children[i]->modelType() == Constants::DetectorContainerType) {
             TransformToDomain::initInstrumentFromDetectorItem(*children[i], P_instrument.get());
         }
     }
diff --git a/GUI/coregui/Models/GUIObjectBuilder.cpp b/GUI/coregui/Models/GUIObjectBuilder.cpp
index 5ca363d7e6a..c22be56c106 100644
--- a/GUI/coregui/Models/GUIObjectBuilder.cpp
+++ b/GUI/coregui/Models/GUIObjectBuilder.cpp
@@ -114,7 +114,7 @@ SessionItem* GUIObjectBuilder::populateInstrumentModel(
 
     // detector
     DetectorContainerItem* detectorItem = dynamic_cast<DetectorContainerItem*>(instrumentModel->insertNewItem(
-        Constants::DetectorType, instrumentModel->indexOfItem(instrumentItem)));
+        Constants::DetectorContainerType, instrumentModel->indexOfItem(instrumentItem)));
     TransformFromDomain::setItemFromSample(detectorItem, simulation);
 
     // detector masks
diff --git a/GUI/coregui/Models/InstrumentItem.cpp b/GUI/coregui/Models/InstrumentItem.cpp
index 75a411dc683..9aed4f92fbd 100644
--- a/GUI/coregui/Models/InstrumentItem.cpp
+++ b/GUI/coregui/Models/InstrumentItem.cpp
@@ -29,7 +29,7 @@ InstrumentItem::InstrumentItem()
     addProperty(P_IDENTIFIER, GUIHelpers::createUuid())->setVisible(false);
 
     const QString T_DATA = "Data tag";
-    registerTag(T_DATA, 0, -1, QStringList() << Constants::BeamType << Constants::DetectorType);
+    registerTag(T_DATA, 0, -1, QStringList() << Constants::BeamType << Constants::DetectorContainerType);
     setDefaultTag(T_DATA);
 }
 
@@ -44,7 +44,7 @@ BeamItem *InstrumentItem::beamItem() const
 DetectorContainerItem *InstrumentItem::detectorItem() const
 {
     for(SessionItem *item : childItems())
-        if(item->modelType() == Constants::DetectorType)
+        if(item->modelType() == Constants::DetectorContainerType)
             return dynamic_cast<DetectorContainerItem *>(item);
     return 0;
 }
diff --git a/GUI/coregui/Models/ItemFactory.cpp b/GUI/coregui/Models/ItemFactory.cpp
index 840f25ca167..c518adc850c 100644
--- a/GUI/coregui/Models/ItemFactory.cpp
+++ b/GUI/coregui/Models/ItemFactory.cpp
@@ -76,7 +76,7 @@ ItemFactory::ItemMap_t initializeItemMap() {
     result[Constants::InterferenceFunction2DLatticeType] = &createInstance<InterferenceFunction2DLatticeItem>;
     result[Constants::InterferenceFunction1DLatticeType] = &createInstance<InterferenceFunction1DLatticeItem>;
     result[Constants::InstrumentType] = &createInstance<InstrumentItem>;
-    result[Constants::DetectorType] = &createInstance<DetectorContainerItem>;
+    result[Constants::DetectorContainerType] = &createInstance<DetectorContainerItem>;
     result[Constants::BeamType] = &createInstance<BeamItem>;
     result[Constants::VectorType] = &createInstance<VectorItem>;
     result[Constants::PropertyType] = &createInstance<PropertyItem>;
@@ -111,7 +111,7 @@ ItemFactory::ItemMap_t initializeItemMap() {
     result[Constants::LayerBasicRoughnessType] = &createInstance<LayerBasicRoughnessItem>;
     result[Constants::LayerZeroRoughnessType] = &createInstance<LayerZeroRoughnessItem>;
 
-    result[Constants::DetectorType] = &createInstance<DetectorContainerItem>;
+    result[Constants::DetectorContainerType] = &createInstance<DetectorContainerItem>;
     result[Constants::SphericalDetectorType] = &createInstance<SphericalDetectorItem>;
     result[Constants::RectangularDetectorType] = &createInstance<RectangularDetectorItem>;
 
diff --git a/GUI/coregui/Models/ModelPath.cpp b/GUI/coregui/Models/ModelPath.cpp
index 2d0be80fa7b..66cdba8dae4 100644
--- a/GUI/coregui/Models/ModelPath.cpp
+++ b/GUI/coregui/Models/ModelPath.cpp
@@ -88,7 +88,7 @@ bool ModelPath::isValidItem(SessionModel* model, SessionItem* item, const QModel
 bool ModelPath::isTranslatable(const SessionItem* item, const QString& par_name)
 {
     Q_UNUSED(item);
-    if (par_name.contains(Constants::DetectorType))
+    if (par_name.contains(Constants::DetectorContainerType))
         return false;
     if (par_name.contains(Constants::DistributionSigmaFactor))
         return false;
diff --git a/GUI/coregui/Models/item_constants.h b/GUI/coregui/Models/item_constants.h
index 41848c8bd30..668e806d409 100644
--- a/GUI/coregui/Models/item_constants.h
+++ b/GUI/coregui/Models/item_constants.h
@@ -38,7 +38,7 @@ const ModelType InterferenceFunction2DParaCrystalType = "Interference2DParaCryst
 const ModelType InterferenceFunction1DLatticeType = "Interference1DLattice";
 const ModelType InterferenceFunction2DLatticeType = "Interference2DLattice";
 const ModelType InstrumentType = "Instrument";
-const ModelType DetectorType = "Detector";
+const ModelType DetectorContainerType = "DetectorContainer";
 const ModelType BeamType = "Beam";
 
 const ModelType FormFactorType = "FormFactor";
diff --git a/GUI/coregui/Views/InstrumentView.cpp b/GUI/coregui/Views/InstrumentView.cpp
index 63ffc3cb695..e346ef7a372 100644
--- a/GUI/coregui/Views/InstrumentView.cpp
+++ b/GUI/coregui/Views/InstrumentView.cpp
@@ -111,7 +111,7 @@ void InstrumentView::onAddInstrument()
     SessionItem *instrument = m_instrumentModel->insertNewItem(Constants::InstrumentType);
     instrument->setItemName(getNewInstrumentName("Default GISAS"));
     m_instrumentModel->insertNewItem(
-        Constants::DetectorType, m_instrumentModel->indexOfItem(instrument));
+        Constants::DetectorContainerType, m_instrumentModel->indexOfItem(instrument));
     m_instrumentModel->insertNewItem(
         Constants::BeamType, m_instrumentModel->indexOfItem(instrument));
     QModelIndex itemIndex = m_instrumentModel->indexOfItem(instrument);
diff --git a/Tests/UnitTests/GUI/TestMapperCases.h b/Tests/UnitTests/GUI/TestMapperCases.h
index 93ca347b3d9..1972912815a 100644
--- a/Tests/UnitTests/GUI/TestMapperCases.h
+++ b/Tests/UnitTests/GUI/TestMapperCases.h
@@ -50,7 +50,7 @@ inline void TestMapperCases::test_instrumentAlignmentPropertyVisibility()
 {
     InstrumentModel model;
     SessionItem *instrument = model.insertNewItem(Constants::InstrumentType);
-    SessionItem *detector = model.insertNewItem(Constants::DetectorType, instrument->index());
+    SessionItem *detector = model.insertNewItem(Constants::DetectorContainerType, instrument->index());
     detector->setGroupProperty(DetectorContainerItem::P_DETECTOR, Constants::RectangularDetectorType);
     SessionItem *rectangular = detector->getGroupItem(DetectorContainerItem::P_DETECTOR);
 
@@ -73,7 +73,7 @@ inline void TestMapperCases::test_removeMaskOnDetectorChange()
 {
     InstrumentModel model;
     SessionItem *instrument = model.insertNewItem(Constants::InstrumentType);
-    SessionItem *detector = model.insertNewItem(Constants::DetectorType, instrument->index());
+    SessionItem *detector = model.insertNewItem(Constants::DetectorContainerType, instrument->index());
     detector->setGroupProperty(DetectorContainerItem::P_DETECTOR, Constants::RectangularDetectorType);
     model.insertNewItem(Constants::MaskContainerType, detector->index());
     QVERIFY(detector->getItems(DetectorContainerItem::T_MASKS).size() == 1);
diff --git a/Tests/UnitTests/GUI/TestSessionModel.h b/Tests/UnitTests/GUI/TestSessionModel.h
index 86ba3313aaa..ca91fd3adcb 100644
--- a/Tests/UnitTests/GUI/TestSessionModel.h
+++ b/Tests/UnitTests/GUI/TestSessionModel.h
@@ -75,12 +75,12 @@ inline void TestSessionModel::test_InstrumentModel_CreateCopy()
     InstrumentModel *model1 = new InstrumentModel();
     SessionItem *instrument1 = model1->insertNewItem(Constants::InstrumentType);
     instrument1->setItemName("instrument1");
-    model1->insertNewItem(Constants::DetectorType, model1->indexOfItem(instrument1));
+    model1->insertNewItem(Constants::DetectorContainerType, model1->indexOfItem(instrument1));
     model1->insertNewItem(Constants::BeamType, model1->indexOfItem(instrument1));
 
     SessionItem *instrument2 = model1->insertNewItem(Constants::InstrumentType);
     instrument2->setItemName("instrument2");
-    model1->insertNewItem(Constants::DetectorType, model1->indexOfItem(instrument2));
+    model1->insertNewItem(Constants::DetectorContainerType, model1->indexOfItem(instrument2));
     model1->insertNewItem(Constants::BeamType, model1->indexOfItem(instrument2));
 
     QString buffer1;
@@ -103,12 +103,12 @@ inline void TestSessionModel::test_InstrumentModel_CreatePartialCopy()
     InstrumentModel *model1 = new InstrumentModel();
     SessionItem *instrument1 = model1->insertNewItem(Constants::InstrumentType);
     instrument1->setItemName("instrument1");
-    model1->insertNewItem(Constants::DetectorType, model1->indexOfItem(instrument1));
+    model1->insertNewItem(Constants::DetectorContainerType, model1->indexOfItem(instrument1));
     model1->insertNewItem(Constants::BeamType, model1->indexOfItem(instrument1));
 
     SessionItem *instrument2 = model1->insertNewItem(Constants::InstrumentType);
     instrument2->setItemName("instrument2");
-    model1->insertNewItem(Constants::DetectorType, model1->indexOfItem(instrument2));
+    model1->insertNewItem(Constants::DetectorContainerType, model1->indexOfItem(instrument2));
     model1->insertNewItem(Constants::BeamType, model1->indexOfItem(instrument2));
 
 //    QString buffer1;
@@ -146,7 +146,7 @@ inline void TestSessionModel::test_copyParameterizedItem()
     InstrumentModel *instrumentModel = new InstrumentModel();
     SessionItem *instrument1 = instrumentModel->insertNewItem(Constants::InstrumentType);
     instrument1->setItemName("instrument1");
-    instrumentModel->insertNewItem(Constants::DetectorType, instrumentModel->indexOfItem(instrument1));
+    instrumentModel->insertNewItem(Constants::DetectorContainerType, instrumentModel->indexOfItem(instrument1));
     instrumentModel->insertNewItem(Constants::BeamType, instrumentModel->indexOfItem(instrument1));
 
     JobModel *jobModel = new JobModel();
-- 
GitLab