diff --git a/Core/Algorithms/inc/Beam.h b/Core/Algorithms/inc/Beam.h
index 11a58878050f6863441b7c1d382ab5c4f0c567b7..526501ff953496993e1b5181a40d3bda04f543fe 100644
--- a/Core/Algorithms/inc/Beam.h
+++ b/Core/Algorithms/inc/Beam.h
@@ -71,6 +71,7 @@ public:
 #endif
 
 protected:
+    virtual void print(std::ostream& ostr) const;
     //! Registers some class members for later access via parameter pool
     virtual void init_parameters();
 
diff --git a/Core/Algorithms/inc/Detector.h b/Core/Algorithms/inc/Detector.h
index acf2197b282209c550d9c4e633eede3aa5b71102..678d813f311fcd0c9942008c4b048cb4992d8777 100644
--- a/Core/Algorithms/inc/Detector.h
+++ b/Core/Algorithms/inc/Detector.h
@@ -78,7 +78,9 @@ public:
             OutputData<Eigen::Matrix2d> *p_polarized_data,
             double sin_alpha_i) const;
 #endif
+
 protected:
+    virtual void print(std::ostream& ostr) const;
 
     //! Registers some class members for later access via parameter pool.
     virtual void init_parameters() {}
diff --git a/Core/Algorithms/inc/Instrument.h b/Core/Algorithms/inc/Instrument.h
index 5cc3a2f25fe78609ed7f7d7dd3ac834bbb3b1305..5b6292b8ad5739a0f95ce9773f658f84f1843960 100644
--- a/Core/Algorithms/inc/Instrument.h
+++ b/Core/Algorithms/inc/Instrument.h
@@ -85,6 +85,8 @@ public:
 #endif
 
 protected:
+    virtual void print(std::ostream& ostr) const;
+
     //! Registers some class members for later access via parameter pool
     virtual void init_parameters();
 
diff --git a/Core/Algorithms/src/Beam.cpp b/Core/Algorithms/src/Beam.cpp
index f549968a3bb581deb551a5474e7a05a84f538120..da1114a37047982006bff6a77ab462e71b3961c5 100644
--- a/Core/Algorithms/src/Beam.cpp
+++ b/Core/Algorithms/src/Beam.cpp
@@ -119,3 +119,8 @@ void Beam::initPolarization()
     m_polarization(1,1) = 0.5;
 }
 
+void Beam::print(std::ostream& ostr) const
+{
+    ostr << "Beam: '" << getName() << "' " << m_parameters;
+}
+
diff --git a/Core/Algorithms/src/Detector.cpp b/Core/Algorithms/src/Detector.cpp
index cb98658c1f73af7b6d013fbcfcfc74f708d42112..70495b50c25a67ff429c90b43e635373b9ff380b 100644
--- a/Core/Algorithms/src/Detector.cpp
+++ b/Core/Algorithms/src/Detector.cpp
@@ -241,4 +241,13 @@ double Detector::getSolidAngle(OutputData<double>* p_data, size_t index) const
     }
 }
 
+void Detector::print(std::ostream& ostr) const
+{
+    ostr << "Detector: '" << getName() << "' " << m_parameters;
+    for(size_t i=0; i<m_axes.size(); ++i) {
+        ostr << "    IAxis:" << *m_axes[i] << std::endl;
+    }
+}
+
+
 
diff --git a/Core/Algorithms/src/Instrument.cpp b/Core/Algorithms/src/Instrument.cpp
index 1c434e091b6cc09b4ebd9fda7a2704748a115119..3469697aa2c27d5401dca958cbf64a6349e9fe08 100644
--- a/Core/Algorithms/src/Instrument.cpp
+++ b/Core/Algorithms/src/Instrument.cpp
@@ -144,4 +144,10 @@ void Instrument::init_parameters()
 {
 }
 
+void Instrument::print(std::ostream& ostr) const
+{
+    ostr << "Instrument: '" << getName() << "' " << m_parameters << std::endl;
+    ostr << "    " << m_beam << std::endl;
+    ostr << "    " << m_detector << std::endl;
+}
 
diff --git a/Core/PythonAPI/src/IAxis.pypp.cpp b/Core/PythonAPI/src/IAxis.pypp.cpp
index 353103be5413bab0b3988e2d25feee80949e4852..32133e4e205ed68787235e6c48b6d32148b0326a 100644
--- a/Core/PythonAPI/src/IAxis.pypp.cpp
+++ b/Core/PythonAPI/src/IAxis.pypp.cpp
@@ -63,6 +63,11 @@ struct IAxis_wrapper : IAxis, bp::wrapper< IAxis > {
         return func___getitem__( index );
     }
 
+    virtual void print( ::std::ostream & ostr ) const {
+        bp::override func_print = this->get_override( "print" );
+        func_print( boost::ref(ostr) );
+    }
+
 };
 
 void register_IAxis_class(){
@@ -156,6 +161,16 @@ void register_IAxis_class(){
                 , bp::pure_virtual( __getitem___function_type(&::IAxis::operator[]) )
                 , ( bp::arg("index") ) );
         
+        }
+        { //::IAxis::print
+        
+            typedef void ( IAxis_wrapper::*print_function_type )( ::std::ostream & ) const;
+            
+            IAxis_exposer.def( 
+                "print"
+                , print_function_type( &IAxis_wrapper::print )
+                , ( bp::arg("ostr") ) );
+        
         }
         { //::IAxis::setName
         
diff --git a/Core/Samples/inc/ISample.h b/Core/Samples/inc/ISample.h
index 37e498527bb46c3b37cdcc05c5fbb67c5a0fa651..90e26d40b377e6d8abfe8da388d15a94afe0dfab 100644
--- a/Core/Samples/inc/ISample.h
+++ b/Core/Samples/inc/ISample.h
@@ -63,8 +63,8 @@ public:
 
     virtual bool containsMagneticMaterial() const;
 
-protected:
-    virtual void print(std::ostream& ostr) const;
+//protected:
+//    virtual void print(std::ostream& ostr) const;
 };
 
 #endif // ISAMPLE_H
diff --git a/Core/Samples/src/ISample.cpp b/Core/Samples/src/ISample.cpp
index c33b52b6405576f8eeca225322cb43da35f6772b..ce071c5c72f83e577a271f76bd9292778cf2bdce 100644
--- a/Core/Samples/src/ISample.cpp
+++ b/Core/Samples/src/ISample.cpp
@@ -76,12 +76,12 @@ bool ISample::containsMagneticMaterial() const
 
 }
 
-void ISample::print(std::ostream& ostr) const
-{
-    ostr << "ISample:" << getName() << "<" << this << ">{ " <<
-        "params={ " << m_parameters << " }";
-    ostr << " }";
-}
+//void ISample::print(std::ostream& ostr) const
+//{
+//    ostr << "ISample:" << getName() << "<" << this << ">{ " <<
+//        "params={ " << m_parameters << " }";
+//    ostr << " }";
+//}
 
 
 
diff --git a/Core/Tools/inc/AxisBin.h b/Core/Tools/inc/AxisBin.h
index 636009f890912115131e257f9cd0e53da7b0c316..7cc78c8e5c233ebf4e196bebd4a0b3722938d04d 100644
--- a/Core/Tools/inc/AxisBin.h
+++ b/Core/Tools/inc/AxisBin.h
@@ -64,6 +64,7 @@ public:
     std::vector<double> getVector() const { return m_value_vector; }
 
 protected:
+    virtual void print(std::ostream& ostr) const;
     virtual bool equals(const IAxis& other) const;
 private:
     std::vector<double> m_value_vector;  //!< vector containing the bin limits
diff --git a/Core/Tools/inc/AxisDouble.h b/Core/Tools/inc/AxisDouble.h
index 110f9b654ac7e9caa1e4bbc314dec248589a125d..1cb8087db2c58bb93001ae8041b26535d72d6f32 100644
--- a/Core/Tools/inc/AxisDouble.h
+++ b/Core/Tools/inc/AxisDouble.h
@@ -75,6 +75,7 @@ public:
     std::vector<double> getVector() const { return m_sample_vector; }
 
 protected:
+    virtual void print(std::ostream& ostr) const;
     virtual bool equals(const IAxis& other) const;
 
 private:
diff --git a/Core/Tools/inc/IAxis.h b/Core/Tools/inc/IAxis.h
index eab3c8327c29952efb51b0bf9dd5281639f51d87..cbe0d5894cdb75e999b0d840db5adde01a0b7146 100644
--- a/Core/Tools/inc/IAxis.h
+++ b/Core/Tools/inc/IAxis.h
@@ -66,7 +66,11 @@ public:
         return left.equals(right);
     }
 
+    friend std::ostream& operator<<(std::ostream& ostr, const IAxis& m)
+    { m.print(ostr); return ostr; }
+
 protected:
+    virtual void print(std::ostream& ostr) const=0;
     virtual bool equals(const IAxis& other) const;
     std::string m_name;  //!< axis label
 };
diff --git a/Core/Tools/inc/IParameterized.h b/Core/Tools/inc/IParameterized.h
index 81172e9182a55c7e7ba8f38cc6fbdd109d931722..22c748580afa6e34c77e08c8bc3593e35ed6005b 100644
--- a/Core/Tools/inc/IParameterized.h
+++ b/Core/Tools/inc/IParameterized.h
@@ -66,7 +66,11 @@ public:
     //! clear parameter pool
     virtual void clearParameterPool() { m_parameters.clear(); }
 
+    friend std::ostream& operator<<(std::ostream& ostr, const IParameterized& m)
+    { m.print(ostr); return ostr; }
+
 protected:
+    virtual void print(std::ostream& ostr) const;
     //! registers class parameters in the parameter pool
     virtual void init_parameters();
 
diff --git a/Core/Tools/src/AxisBin.cpp b/Core/Tools/src/AxisBin.cpp
index 1f32c87688794a47121573e93917d7640b1b3586..4817331edeb59f264ba619e10a443a9c81abf3a2 100644
--- a/Core/Tools/src/AxisBin.cpp
+++ b/Core/Tools/src/AxisBin.cpp
@@ -110,4 +110,9 @@ bool AxisBin::equals(const IAxis& other) const
     return false;
 }
 
+void AxisBin::print(std::ostream& ostr) const
+{
+    ostr << "AxisBin '" << m_name << "'" << getSize() << " " << getMin() << " " << getMax();
+}
+
 
diff --git a/Core/Tools/src/AxisDouble.cpp b/Core/Tools/src/AxisDouble.cpp
index d463f696498c2568aa8040daa4f44ee771411b29..ea1dd383a5074dd5d23d8207f7ac9dc0812adf41 100644
--- a/Core/Tools/src/AxisDouble.cpp
+++ b/Core/Tools/src/AxisDouble.cpp
@@ -131,4 +131,8 @@ bool AxisDouble::equals(const IAxis& other) const
     return false;
 }
 
+void AxisDouble::print(std::ostream& ostr) const
+{
+    ostr << "AxisDouble '" << m_name << "'" << getSize() << " " << getMin() << " " << getMax();
+}
 
diff --git a/Core/Tools/src/IParameterized.cpp b/Core/Tools/src/IParameterized.cpp
index 0071d0f829c6ef015f0b7f84dfde5e9c037fb215..86570b0029d85b0daaa5c66b3a8cc18c1f34213a 100644
--- a/Core/Tools/src/IParameterized.cpp
+++ b/Core/Tools/src/IParameterized.cpp
@@ -87,6 +87,10 @@ void IParameterized::init_parameters()
                                   "Error! Method is not implemented");
 }
 
+void IParameterized::print(std::ostream& ostr) const
+{
+    ostr << "IParameterized:" << getName() << " " << m_parameters;
+}
 
 
 
diff --git a/GUI/coregui/Models/DetectorItems.cpp b/GUI/coregui/Models/DetectorItems.cpp
index c85c8ed82bebcc4a72e64794d684d38583814043..0506b3ea90585a46486cb7ecaaab164915dbbb33 100644
--- a/GUI/coregui/Models/DetectorItems.cpp
+++ b/GUI/coregui/Models/DetectorItems.cpp
@@ -8,7 +8,14 @@ const QString DetectorItem::P_AXES_UNITS = "Units";
 const QString DetectorItem::P_BINNING = "Binning";
 
 const QString XYDetectorItem::P_MODEL_TYPE = "X, Y plane";
+
 const QString ThetaPhiDetectorItem::P_MODEL_TYPE = "Theta, Phi plane";
+const QString ThetaPhiDetectorItem::P_NPHI = "Phi, nbins";
+const QString ThetaPhiDetectorItem::P_PHI_MIN = "Phi, min";
+const QString ThetaPhiDetectorItem::P_PHI_MAX = "Phi, max";
+const QString ThetaPhiDetectorItem::P_NALPHA = "Alpha, nbins";
+const QString ThetaPhiDetectorItem::P_ALPHA_MIN = "Alpha, min";
+const QString ThetaPhiDetectorItem::P_ALPHA_MAX = "Alpha, max";
 
 DetectorItem::DetectorItem(ParameterizedItem *parent)
     : ParameterizedItem(QString("Detector"), parent)
@@ -46,11 +53,18 @@ ThetaPhiDetectorItem::ThetaPhiDetectorItem(ParameterizedItem *parent)
     setItemName("ThetaPhiDetector");
 
     ComboProperty units;
-    units << "Degrees" << "Radians";
+    units << "Degrees";
     registerProperty(DetectorItem::P_AXES_UNITS, units.getVariant());
 
     ComboProperty binning;
     binning << "Flat" << "Flat in sin";
     registerProperty(DetectorItem::P_BINNING, binning.getVariant());
 
+    registerProperty(P_NPHI, 100);
+    registerProperty(P_PHI_MIN, -1.0);
+    registerProperty(P_PHI_MAX,  1.0);
+    registerProperty(P_NALPHA, 100);
+    registerProperty(P_ALPHA_MIN, 0.0);
+    registerProperty(P_ALPHA_MAX,  2.0);
 }
+
diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h
index 353a02c93210a59d764b41e60f2d3bc3df410a31..3714bb8aec0caadacbc0a93db1cc989c33d7df5f 100644
--- a/GUI/coregui/Models/DetectorItems.h
+++ b/GUI/coregui/Models/DetectorItems.h
@@ -31,7 +31,7 @@ class ThetaPhiDetectorItem : public ParameterizedItem
 {
     Q_OBJECT
 public:
-    static const QString P_MODEL_TYPE;
+    static const QString P_MODEL_TYPE, P_PHI_MIN, P_PHI_MAX, P_NPHI, P_ALPHA_MIN, P_ALPHA_MAX, P_NALPHA;
     explicit ThetaPhiDetectorItem(ParameterizedItem *parent=0);
     ~ThetaPhiDetectorItem(){}
 
diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp
index 2bff955dcf46f48d43cae055e1ef0aa471d3563c..1ee307780ac27bdeeab8ccf8bca7bcf0954fc19e 100644
--- a/GUI/coregui/Models/DomainObjectBuilder.cpp
+++ b/GUI/coregui/Models/DomainObjectBuilder.cpp
@@ -22,6 +22,7 @@
 
 DomainObjectBuilder::DomainObjectBuilder()
     : mp_sample(0)
+    , m_instrument(0)
 {
 
 }
@@ -29,16 +30,21 @@ DomainObjectBuilder::DomainObjectBuilder()
 DomainObjectBuilder::~DomainObjectBuilder()
 {
     delete mp_sample;
+    delete m_instrument;
 }
 
 void DomainObjectBuilder::buildItem(const ParameterizedItem &item)
 {
-    if (item.modelType() == QString("MultiLayer")) {
+    if (item.modelType() == QStringLiteral("MultiLayer")) {
         delete mp_sample;
         mp_sample = buildMultiLayer(item);
     }
+    else if(item.modelType() == QStringLiteral("MultiLayer")) {
+        delete m_instrument;
+        m_instrument = buildInstrument(item);
+    }
     else {
-        // not a suitable top level object (throw?)
+        throw GUIHelpers::Error("DomainObjectBuilder::buildItem() -> Error. Not a suitable top level object.");
     }
 }
 
@@ -118,3 +124,34 @@ IInterferenceFunction *DomainObjectBuilder::buildInterferenceFunction(const Para
     return result;
 }
 
+
+Instrument *DomainObjectBuilder::buildInstrument(const ParameterizedItem &item) const
+{
+    qDebug() << "DomainObjectBuilder::buildInstrument";
+    Instrument *result = TransformToDomain::createInstrument(item);
+    QList<ParameterizedItem *> children = item.childItems();
+    for (int i=0; i<children.size(); ++i) {
+        qDebug() << "   DomainObjectBuilder::buildInstrument" << children[i]->modelType();
+        if (children[i]->modelType() == QString("Beam")) {
+            boost::scoped_ptr<Beam> P_beam(buildBeam(*children[i]));
+            if (P_beam.get()) {
+                result->setBeam(*P_beam);
+            }
+        }
+        else if (children[i]->modelType() == QString("Detector")) {
+            TransformToDomain::initInstrumentFromDetectorItem(*children[i], result);
+        }
+
+    }
+
+    return result;
+}
+
+Beam *DomainObjectBuilder::buildBeam(const ParameterizedItem &item) const
+{
+    qDebug() << "DomainObjectBuilder::buildBeam()";
+    Beam *result = TransformToDomain::createBeam(item);
+    return result;
+}
+
+
diff --git a/GUI/coregui/Models/DomainObjectBuilder.h b/GUI/coregui/Models/DomainObjectBuilder.h
index 1ede82b8892225aadc8e74f715d5f2d758d4c767..53686776749cb0fd80ef6fb2d5f834b3185532f2 100644
--- a/GUI/coregui/Models/DomainObjectBuilder.h
+++ b/GUI/coregui/Models/DomainObjectBuilder.h
@@ -17,6 +17,7 @@
 #define DOMAINOBJECTBUILDER_H
 
 #include "Samples.h"
+#include "Instrument.h"
 #include "InterferenceFunctions.h"
 #include "ParameterizedItem.h"
 
@@ -28,17 +29,21 @@ public:
 
     void buildItem(const ParameterizedItem &item);
 
-    ISample *getSample() {
-        return mp_sample;
-    }
+    ISample *getSample() { return mp_sample; }
+    Instrument *getInstrument() { return m_instrument; }
 
-private:
     MultiLayer *buildMultiLayer(const ParameterizedItem &item) const;
+    Instrument *buildInstrument(const ParameterizedItem &item) const;
+
+private:
     Layer *buildLayer(const ParameterizedItem &item) const;
     ParticleLayout *buildParticleLayout(const ParameterizedItem &item) const;
     Particle *buildParticle(const ParameterizedItem &item, double &depth, double &abundance) const;
     IInterferenceFunction *buildInterferenceFunction(const ParameterizedItem &item) const;
+    Beam *buildBeam(const ParameterizedItem &item) const;
+
     ISample *mp_sample;
+    Instrument *m_instrument;
 };
 
 #endif // DOMAINOBJECTBUILDER_H
diff --git a/GUI/coregui/Models/ParameterizedItem.cpp b/GUI/coregui/Models/ParameterizedItem.cpp
index afb6e919eaca9963e35f2ae412418b57cea2c209..1a523132dbfb49a2259a56fd7db0da29fff3b603 100644
--- a/GUI/coregui/Models/ParameterizedItem.cpp
+++ b/GUI/coregui/Models/ParameterizedItem.cpp
@@ -237,3 +237,21 @@ void ParameterizedItem::setPropertyVisibility(const QString &name, PropertyVisib
 
     }
 }
+
+void ParameterizedItem::print() const
+{
+    qDebug() << "--- ParameterizedItem::print() ------------------------------------";
+    qDebug() << modelType() << itemName();
+    qDebug() << "--- SubItems ---";
+    for(QMap<QString, ParameterizedItem *>::const_iterator it=m_sub_items.begin(); it!=m_sub_items.end(); ++it) {
+        qDebug() << "   key:" << it.key() << " value:" << it.value()->modelType();
+    }
+    qDebug() << "--- Properties ---";
+    QList<QByteArray> property_names = dynamicPropertyNames();
+    for (int i = 0; i < property_names.length(); ++i) {
+        QString name(property_names[i]);
+        qDebug() << name << property(name.toUtf8().constData());
+    }
+    qDebug() << " ";
+
+}
diff --git a/GUI/coregui/Models/ParameterizedItem.h b/GUI/coregui/Models/ParameterizedItem.h
index 905f63b71a54ed1df60a9f199c0a933fde5d2c9d..669266cfb6a29e60baee82c1956609d0672d2bd5 100644
--- a/GUI/coregui/Models/ParameterizedItem.h
+++ b/GUI/coregui/Models/ParameterizedItem.h
@@ -115,6 +115,7 @@ public:
 
     void setPropertyVisibility(const QString &name, PropertyVisibility visibility);
 
+    void print() const;
 signals:
     void propertyChanged(const QString &propertyName);
     void propertyItemChanged(const QString &propertyName);
diff --git a/GUI/coregui/Models/SessionModel.cpp b/GUI/coregui/Models/SessionModel.cpp
index 06073d933d90cfb03cbac6f52b1e60641e3870d6..bf9b7114e09bb441df3a5959e923bc056c7814d4 100644
--- a/GUI/coregui/Models/SessionModel.cpp
+++ b/GUI/coregui/Models/SessionModel.cpp
@@ -475,10 +475,14 @@ QString SessionModel::readProperty(QXmlStreamReader *reader, ParameterizedItem *
         double parameter_value = reader->attributes()
                 .value(SessionXML::ParameterValueAttribute)
                 .toDouble();
-        //qDebug() << "           SessionModel::readProperty " << parameter_name << parameter_type << parameter_value;
-//        item->setProperty(parameter_name.toUtf8().constData(),
-//                          parameter_value);
         item->setRegisteredProperty(parameter_name, parameter_value);
+
+    }
+    else if (parameter_type == "int") {
+            double parameter_value = reader->attributes()
+                    .value(SessionXML::ParameterValueAttribute)
+                    .toInt();
+            item->setRegisteredProperty(parameter_name, parameter_value);
     }
     else if (parameter_type == "bool") {
         bool parameter_value = reader->attributes()
@@ -576,6 +580,10 @@ void SessionModel::writeProperty(QXmlStreamWriter *writer,
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                 QString::number(variant.toDouble(), 'e', 12));
         }
+        else if (type_name == QString("int")) {
+            writer->writeAttribute(SessionXML::ParameterValueAttribute,
+                                QString::number(variant.toInt()));
+        }
         else if (type_name == QString("bool")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                 QString::number(variant.toBool()));
diff --git a/GUI/coregui/Models/SimulationDataModel.cpp b/GUI/coregui/Models/SimulationDataModel.cpp
index 5a6af987b4510827736437d1a82ecce454794693..3f2c2c1e39a19be1d8aa89c39db7775d2e6681eb 100644
--- a/GUI/coregui/Models/SimulationDataModel.cpp
+++ b/GUI/coregui/Models/SimulationDataModel.cpp
@@ -30,9 +30,7 @@ void SimulationDataModel::clear()
 
 void SimulationDataModel::addSample(QString name, ISample *p_sample)
 {
-//    if (!m_samples.contains(name)) {
-        m_samples.insertMulti(name, p_sample);
-//    }
+    m_samples.insertMulti(name, p_sample);
 }
 
 void SimulationDataModel::addSampleBuilder(QString name, ISampleBuilder *p_sample_builder)
@@ -44,9 +42,7 @@ void SimulationDataModel::addSampleBuilder(QString name, ISampleBuilder *p_sampl
 
 void SimulationDataModel::addInstrument(QString name, Instrument *p_instrument)
 {
-    if (!m_instruments.contains(name)) {
-        m_instruments.insert(name, p_instrument);
-    }
+    m_instruments.insertMulti(name, p_instrument);
 }
 
 void SimulationDataModel::changeInstrument(QString name, Instrument *p_instrument)
diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp
index 37ec56bfa463ff6829cb2a5e749c683702df56dd..aef4178a7d898d0b4f24918b25e6bef666675da7 100644
--- a/GUI/coregui/Models/TransformToDomain.cpp
+++ b/GUI/coregui/Models/TransformToDomain.cpp
@@ -20,6 +20,10 @@
 #include "ParaCrystalItems.h"
 #include "ParticleItem.h"
 #include "LayerItem.h"
+#include "BeamItem.h"
+#include "GroupProperty.h"
+#include "ComboProperty.h"
+#include "DetectorItems.h"
 #include "MultiLayerItem.h"
 #include "LatticeTypeItems.h"
 #include "FTDistributionItems.h"
@@ -166,3 +170,66 @@ IInterferenceFunction *TransformToDomain::createInterferenceFunction(const Param
 
 
 
+
+
+Instrument *TransformToDomain::createInstrument(const ParameterizedItem &item)
+{
+    qDebug() << "TransformToDomain::createInstrument";
+    Instrument *result = new Instrument();
+    result->setName(item.itemName().toUtf8().constData());
+    return result;
+}
+
+
+
+Beam *TransformToDomain::createBeam(const ParameterizedItem &item)
+{
+    qDebug() << "TransformToDomain::createBeam";
+    Beam *result = new Beam();
+    result->setName(item.itemName().toUtf8().constData());
+    result->setIntensity(item.getRegisteredProperty(BeamItem::P_INTENSITY).toDouble());
+    double lambda = item.getRegisteredProperty(BeamItem::P_WAVELENGTH).toDouble();
+    double alpha_i = item.getRegisteredProperty(BeamItem::P_INCLINATION_ANGLE).toDouble();
+    double phi_i = item.getRegisteredProperty(BeamItem::P_AZIMUTHAL_ANGLE).toDouble();
+    result->setCentralK( lambda, Units::deg2rad(alpha_i), Units::deg2rad(phi_i));
+    return result;
+}
+
+
+
+void TransformToDomain::initInstrumentFromDetectorItem(const ParameterizedItem &item, Instrument *instrument)
+{
+    qDebug() << "TransformToDomain::initInstrumentWithDetectorItem()" << item.modelType();
+    item.print();
+
+    ParameterizedItem *subDetector = item.getSubItems()[DetectorItem::P_DETECTOR_TYPE];
+    Q_ASSERT(subDetector);
+
+    qDebug() << "   TransformToDomain::initInstrumentWithDetectorItem()" << subDetector->modelType();
+    if (subDetector->modelType() == ThetaPhiDetectorItem::P_MODEL_TYPE) {
+        int nphi = subDetector->getRegisteredProperty(ThetaPhiDetectorItem::P_NPHI).toInt();
+        double phi_min = subDetector->getRegisteredProperty(ThetaPhiDetectorItem::P_PHI_MIN).toDouble();
+        double phi_max = subDetector->getRegisteredProperty(ThetaPhiDetectorItem::P_PHI_MAX).toDouble();
+        int nalpha = subDetector->getRegisteredProperty(ThetaPhiDetectorItem::P_NALPHA).toInt();
+        double alpha_min = subDetector->getRegisteredProperty(ThetaPhiDetectorItem::P_ALPHA_MIN).toDouble();
+        double alpha_max = subDetector->getRegisteredProperty(ThetaPhiDetectorItem::P_ALPHA_MAX).toDouble();
+        bool isgisaxs_style(true);
+
+        ComboProperty binning = subDetector->getRegisteredProperty(DetectorItem::P_BINNING).value<ComboProperty>();
+        if(binning.getValue() == QStringLiteral("Flat")) isgisaxs_style = false;
+
+        ComboProperty units = subDetector->getRegisteredProperty(DetectorItem::P_AXES_UNITS).value<ComboProperty>();
+        if(units.getValue() == QStringLiteral("Degrees")) {
+            phi_min = Units::deg2rad(phi_min);
+            phi_max = Units::deg2rad(phi_max);
+            alpha_min = Units::deg2rad(alpha_min);
+            alpha_max = Units::deg2rad(alpha_max);
+        }
+
+        instrument->setDetectorParameters(nphi, phi_min, phi_max, nalpha, alpha_min, alpha_max, isgisaxs_style);
+    }
+    else {
+        throw GUIHelpers::Error("TransformToDomain::initInstrumentWithDetectorItem() -> Error. Unknown model type "+subDetector->modelType());
+    }
+
+}
diff --git a/GUI/coregui/Models/TransformToDomain.h b/GUI/coregui/Models/TransformToDomain.h
index 0ee669a7c6fd07571daace5dea72dd982ce55acb..dfaad61e95e0e80cde719676ee28dd1ecf75119a 100644
--- a/GUI/coregui/Models/TransformToDomain.h
+++ b/GUI/coregui/Models/TransformToDomain.h
@@ -19,6 +19,7 @@
 #include "Samples.h"
 #include "InterferenceFunctions.h"
 #include "ParameterizedItem.h"
+#include "Instrument.h"
 
 namespace TransformToDomain
 {
@@ -29,6 +30,9 @@ ParticleLayout *createParticleLayout(const ParameterizedItem &item);
 Particle *createParticle(const ParameterizedItem &item, double &depth, double &abundance);
 IFormFactor *createFormFactor(const ParameterizedItem &item);
 IInterferenceFunction *createInterferenceFunction(const ParameterizedItem &item);
+Instrument *createInstrument(const ParameterizedItem &item);
+Beam *createBeam(const ParameterizedItem &item);
+void initInstrumentFromDetectorItem(const ParameterizedItem &item, Instrument *instrument);
 }
 
 #endif // TRANSFORMTODOMAIN_H
diff --git a/GUI/coregui/Views/SimulationView.cpp b/GUI/coregui/Views/SimulationView.cpp
index 3f94b803f408b471f867a55bfd0d4aac4fe2da97..fc2ec25192fb3875b467480514eee39bc0709791 100644
--- a/GUI/coregui/Views/SimulationView.cpp
+++ b/GUI/coregui/Views/SimulationView.cpp
@@ -124,7 +124,13 @@ void SimulationView::setJobQueueModel(JobQueueModel *model)
 void SimulationView::updateViewElements()
 {
     instrumentSelectionBox->clear();
-    instrumentSelectionBox->addItems(mp_simulation_data_model->getInstrumentList().keys());
+    if(mp_simulation_data_model->getInstrumentList().isEmpty()) {
+        instrumentSelectionBox->addItem("No instrument defined yet");
+        instrumentSelectionBox->setEnabled(false);
+    } else {
+        instrumentSelectionBox->setEnabled(true);
+        instrumentSelectionBox->addItems(mp_simulation_data_model->getInstrumentList().keys());
+    }
 
     sampleSelectionBox->clear();
     if(mp_simulation_data_model->getSampleList().isEmpty()) {
diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp
index d0a21f547aaddcf55c07d45d762a8e3e3717d024..49d1d353d6c7797fbd9c3b68bbf461eceb38eb2a 100644
--- a/GUI/coregui/mainwindow/mainwindow.cpp
+++ b/GUI/coregui/mainwindow/mainwindow.cpp
@@ -206,21 +206,21 @@ void MainWindow::initSimModel()
 {
     if (mp_sim_data_model) delete mp_sim_data_model;
     mp_sim_data_model = new SimulationDataModel;
-    mp_sim_data_model->addInstrument(tr("Default GISAS"), createDefaultInstrument());
+    //mp_sim_data_model->addInstrument(tr("Default GISAS"), createDefaultInstrument());
     //mp_sim_data_model->addSample(tr("Default cylinder single layer"), createDefaultSample());
 }
 
-Instrument *MainWindow::createDefaultInstrument()
-{
-    Instrument *p_result = new Instrument;
-    p_result->setBeamParameters(0.1*Units::nanometer, 0.2*Units::degree, 0.0);
-    p_result->setBeamIntensity(1e7);
-//    p_result->setDetectorParameters(100, -1.0*Units::degree, 1.0*Units::degree,
-//                                    100, 0.0*Units::degree, 2.0*Units::degree);
-    p_result->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree,
-                                    100, 0.0*Units::degree, 2.0*Units::degree, true);
-    return p_result;
-}
+//Instrument *MainWindow::createDefaultInstrument()
+//{
+//    Instrument *p_result = new Instrument;
+//    p_result->setBeamParameters(0.1*Units::nanometer, 0.2*Units::degree, 0.0);
+//    p_result->setBeamIntensity(1e7);
+////    p_result->setDetectorParameters(100, -1.0*Units::degree, 1.0*Units::degree,
+////                                    100, 0.0*Units::degree, 2.0*Units::degree);
+//    p_result->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree,
+//                                    100, 0.0*Units::degree, 2.0*Units::degree, true);
+//    return p_result;
+//}
 
 
 void MainWindow::initJobQueueModel()
@@ -324,12 +324,17 @@ void MainWindow::updateSimModel()
 {
     Q_ASSERT(mp_sim_data_model);
     Q_ASSERT(m_sampleModel);
-
+    Q_ASSERT(m_instrumentModel);
     qDebug() << " ";
     qDebug() << "MainWindow::updateSimModel()" << m_sampleModel->rowCount( QModelIndex() );
-
     mp_sim_data_model->clear();
+    updateSamples();
+    updateInstruments();
+}
 
+
+void MainWindow::updateSamples()
+{
     QModelIndex parentIndex;
     for( int i_row = 0; i_row < m_sampleModel->rowCount( parentIndex); ++i_row) {
          QModelIndex itemIndex = m_sampleModel->index( i_row, 0, parentIndex );
@@ -338,17 +343,36 @@ void MainWindow::updateSimModel()
              qDebug() << item->itemName() << item->modelType();
              if(item->modelType() == "MultiLayer") {
                  DomainObjectBuilder builder;
-                 builder.buildItem(*item);
-                 MultiLayer *multilayer = dynamic_cast<MultiLayer *>(builder.getSample());
+                 MultiLayer *multilayer = builder.buildMultiLayer(*item);
                  multilayer->printSampleTree();
                  if(multilayer) {
-                     mp_sim_data_model->addSample(item->itemName(), multilayer->clone());
+                     mp_sim_data_model->addSample(item->itemName(), multilayer);
                  }
              }
          }
     }
+}
+
 
-    mp_sim_data_model->addInstrument(tr("Default GISAS"), createDefaultInstrument());
+void MainWindow::updateInstruments()
+{
+    qDebug() << "MainWindow::updateInstruments()";
+    QModelIndex parentIndex;
+    for( int i_row = 0; i_row < m_instrumentModel->rowCount( parentIndex); ++i_row) {
+         QModelIndex itemIndex = m_instrumentModel->index( i_row, 0, parentIndex );
+
+         if (ParameterizedItem *item = m_instrumentModel->itemForIndex(itemIndex)){
+             qDebug() << "      MainWindow::updateInstruments()" << item->itemName() << item->modelType();
+             if(item->modelType() == "Instrument") {
+                 DomainObjectBuilder builder;
+                 Instrument *instrument = builder.buildInstrument(*item);
+                 std::cout << *instrument << std::endl;
+                 if(instrument) {
+                     mp_sim_data_model->addInstrument(item->itemName(), instrument);
+                 }
+             }
+         }
+    }
 }
 
 
diff --git a/GUI/coregui/mainwindow/mainwindow.h b/GUI/coregui/mainwindow/mainwindow.h
index 3e51f84132abeca76de663441a0e9c1888537cc3..a25dc83f0ef64e7fb2c010da9301e7ad3837b59a 100644
--- a/GUI/coregui/mainwindow/mainwindow.h
+++ b/GUI/coregui/mainwindow/mainwindow.h
@@ -93,12 +93,15 @@ private:
     void initInstrumentModel();
     void initMaterialModel();
 
+    void updateSimModel();
+    void updateSamples();
+    void updateInstruments();
+
     void testGUIObjectBuilder();
 
-    void updateSimModel();
 
     // dummy instrument creator
-    Instrument *createDefaultInstrument();
+//    Instrument *createDefaultInstrument();
 //    ISample *createDefaultSample();
 };