// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | contact@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object linking the spectral line calculation configuration parameters in the main calculation module with the QML interface component
#include "lineoptionsdataobject.h"
#include <QMessageBox>
#include <QLocale>
#include <QString>
#include <QLocale>
#include "math.h"

LineOptionsDataObject::LineOptionsDataObject(QObject *parent, BytranCore *inCore) : QObject(parent)
{
    // Passing in the core object
    core = inCore;

    // So that commas are not inserted into numbers
    loc.setNumberOptions(QLocale::OmitGroupSeparator);

    // Saving lineshape profile
    m_lineshapeProfile = core->getParams()->getLineshapeProfile();

    // Transfering the intensity treshold data to the QML interface component
    m_intensTresh = loc.toString(core->getParams()->getIntensThresh() * 1E+25, 'g', 6);

    // Transfering the line wing contribution saturated in halfwidths data to the QML interface component
    m_wingContribSatHw = loc.toString(core->getParams()->getWingContribSatHw());

    // Transfering the line wing contribution absolute data to the QML interface component
    m_wingContribAbs = loc.toString(core->getParams()->getWingContribAbs(), 'g', 6);

    // Saving line broadening data
    m_lineBroadening = core->getParams()->getLineBroadening();

    // Saving line shift data
    m_useLineShift = core->getParams()->getUseLineShift();

}

LineOptionsDataObject::LineOptionsDataObject(const QString &intensThresh, const QString &wingContribSatHw, const QString &wingContribAbs, const int &lineshapeProfile, const int &lineBroadening, const bool &useLineShift, QObject *parent)
    : QObject(parent), m_intensTresh(intensThresh), m_wingContribSatHw(wingContribSatHw), m_wingContribAbs(wingContribAbs), m_lineshapeProfile(lineshapeProfile), m_lineBroadening(lineBroadening), m_useLineShift(useLineShift)
{
    ;
}

QString LineOptionsDataObject::intensThresh() const
{
    return m_intensTresh;
}
void LineOptionsDataObject::setIntensThresh(const QString &intensTresh)
{
    if (intensTresh != m_intensTresh) {
        m_intensTresh = intensTresh;
        // Saving the wavelength into the internal dataset variable
        core->getParams()->setIntensThresh(loc.toDouble(m_intensTresh) * 1E-25);
        emit intensThreshChanged();
    }
}

QString LineOptionsDataObject::wingContribSatHw() const
{
    return m_wingContribSatHw;
}
void LineOptionsDataObject::setWingContribSatHw(const QString &wingContribSatHw)
{
    if (wingContribSatHw != m_wingContribSatHw) {
        m_wingContribSatHw = wingContribSatHw;
        // Saving the wavelength into the internal dataset variable
        core->getParams()->setWingContribSatHw(loc.toDouble(m_wingContribSatHw));
        emit wingContribSatHwChanged();
    }
}

QString LineOptionsDataObject::wingContribAbs() const
{
    return m_wingContribAbs;
}
void LineOptionsDataObject::setWingContribAbs(const QString &wingContribAbs)
{
    if (wingContribAbs != m_wingContribAbs) {
        m_wingContribAbs = wingContribAbs;
        // Saving the wavelength into the internal dataset variable
        core->getParams()->setWingContribAbs(loc.toDouble(m_wingContribAbs));
        emit wingContribAbsChanged();
    }
}

int LineOptionsDataObject::lineshapeProfile() const
{
    return m_lineshapeProfile;
}

void LineOptionsDataObject::setLineshapeProfile(const int &lineshapeProfile)
{
    if (lineshapeProfile != m_lineshapeProfile) {

        m_lineshapeProfile = lineshapeProfile;
        // Saving the units into the object used to convert to different pathlength measurement units
        core->getParams()->setLineshapeProfile(m_lineshapeProfile);

        emit lineshapeProfileChanged();
    }
}

int LineOptionsDataObject::lineBroadening() const
{
    return m_lineBroadening;
}

void LineOptionsDataObject::setLineBroadening(const int &lineBroadening)
{
    if (lineBroadening != m_lineBroadening) {

        m_lineBroadening = lineBroadening;
        // Saving the units into the object used to convert to different pathlength measurement units
        core->getParams()->setLineBroadening(m_lineBroadening);

        // Emitting signals to update values
        emit lineBroadeningChanged();
    }
}

bool LineOptionsDataObject::useLineShift() const
{
    return m_useLineShift;
}

void LineOptionsDataObject::setUseLineShift(const bool &useLineShift)
{
    if (useLineShift != m_useLineShift) {

        m_useLineShift = useLineShift;
        // Saving the units into the object used to convert to different pathlength measurement units
        core->getParams()->setUseLineShift(m_useLineShift);

        // Emitting signals to update values
        emit useLineShiftChanged();
    }
}
