Skip to content
Snippets Groups Projects
InstrumentBuilder.h 3.52 KiB
Newer Older
#ifndef MANTIDNEXUSGEOMETRY_INSTRUMENTBUILDER_H
#define MANTIDNEXUSGEOMETRY_INSTRUMENTBUILDER_H
#include "MantidNexusGeometry/DllConfig.h"
#include "MantidGeometry/Objects/IObject.h"
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <memory>
Owen Arnold's avatar
Owen Arnold committed
namespace Mantid {
namespace Geometry {
class Instrument;
class IComponent;
class ICompAssembly;
Owen Arnold's avatar
Owen Arnold committed
namespace NexusGeometry {
namespace detail {
class Tube;
}
/** InstrumentBuilder : Builder for wrapping the creating of a Mantid
  Instrument. Provides some useful abstractions over the full-blown Instrument
  interface

  Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
  National Laboratory & European Spallation Source

  This file is part of Mantid.

  Mantid is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  Mantid is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

  File change history is stored at: <https://github.com/mantidproject/mantid>
  Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_NEXUSGEOMETRY_DLL InstrumentBuilder {
Owen Arnold's avatar
Owen Arnold committed
public:
  /// Constructor creates the instrument
  explicit InstrumentBuilder(const std::string &instrumentName);
Owen Arnold's avatar
Owen Arnold committed
  /// Adds component to instrument
Owen Arnold's avatar
Owen Arnold committed
  Geometry::IComponent *addComponent(const std::string &compName,
                                     const Eigen::Vector3d &position);

  void addObjComponentAssembly(
      const std::string &compName, const detail::Tube &tube,
      boost::shared_ptr<const Mantid::Geometry::IObject> detShape);
  /// Adds detector to the root (instrument)
  void addDetectorToInstrument(
      const std::string &detName, int detId, const Eigen::Vector3d &position,
      boost::shared_ptr<const Mantid::Geometry::IObject> &shape);
  /// Adds detector to the last registered bank
  void addDetectorToLastBank(
      const std::string &detName, int detId,
      const Eigen::Vector3d &relativeOffset,
      boost::shared_ptr<const Mantid::Geometry::IObject> shape);
Owen Arnold's avatar
Owen Arnold committed
  /// Adds detector to instrument
  void addMonitor(const std::string &detName, int detId,
                  const Eigen::Vector3d &position,
                  boost::shared_ptr<const Mantid::Geometry::IObject> &shape);
Owen Arnold's avatar
Owen Arnold committed
  /// Add sample
Owen Arnold's avatar
Owen Arnold committed
  void addSample(const std::string &sampleName,
                 const Eigen::Vector3d &position);
Owen Arnold's avatar
Owen Arnold committed
  /// Add source
Owen Arnold's avatar
Owen Arnold committed
  void addSource(const std::string &sourceName,
                 const Eigen::Vector3d &position);

  void addBank(const std::string &localName, const Eigen::Vector3d &position,
               const Eigen::Quaterniond &rotation);

Owen Arnold's avatar
Owen Arnold committed
  /// Returns underlying instrument
  std::unique_ptr<const Geometry::Instrument> createInstrument() const;
Owen Arnold's avatar
Owen Arnold committed

private:
  /// Sorts detectors
  void sortDetectors() const;
  /// Check that this instance is not locked
  void verifyMutable() const;
  /// product
  mutable std::unique_ptr<Geometry::Instrument> m_instrument;
  /// Last bank added. The instrument is the owner of the bank.
  Geometry::ICompAssembly *m_lastBank = nullptr;
  /// completed
  mutable bool m_finalized = false;
#endif // MANTIDNEXUSGEOMETRY_INSTRUMENTBUILDER_H