//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/Model/Mask/MaskUnitsConverter.h
//! @brief     Defines class MaskUnitsConverter
//!
//! @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_DATA_MASKUNITSCONVERTER_H
#define BORNAGAIN_GUI_MODEL_DATA_MASKUNITSCONVERTER_H

class Frame;
class MaskItem;

//! The MaskUnitsConverter converts coordinates of all masks from one units to another.
//! I.e. masks in 'mm' into masks in 'deg'. This is done in two steps.
//! On first step masks are converted from native coordinates (as given by axes of Datafield)
//! into bin-fraction coordinates.
//! On second step masks are converted from bin-fraction coordinates into current axes of
//! Datafield.

class MaskUnitsConverter {
public:
    MaskUnitsConverter(const Frame& frame);

    void convertToNbins(MaskItem* maskItem);
    void convertFromNbins(MaskItem* maskItem);

private:
    enum class Axis { X, Y };
    enum EConversionDirection { TO_NBINS, FROM_NBINS, UNDEFINED };

    void convertMask(MaskItem* maskItem);

    double convert(double value, Axis axis);

    const Frame& m_frame;
    EConversionDirection m_direction;
};

#endif // BORNAGAIN_GUI_MODEL_DATA_MASKUNITSCONVERTER_H
