summaryrefslogtreecommitdiffstats
path: root/src/tests/common_tev.c
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2013-08-31 01:12:01 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-09-09 16:30:53 +0200
commit84ef91035f36ca6aed70d17da170d323880c5393 (patch)
treefe33c97ce01603054c554839107daca1ea943448 /src/tests/common_tev.c
parent9dbdf62243f01f6aee41c2b5f2976c56da47f25d (diff)
downloadsssd-84ef91035f36ca6aed70d17da170d323880c5393.tar.gz
sssd-84ef91035f36ca6aed70d17da170d323880c5393.tar.xz
sssd-84ef91035f36ca6aed70d17da170d323880c5393.zip
AUTOTOOLS: add check for type intptr_t
We check whether HAVE_INTPTR_T is defined in definition of macro discard_const_p, but autootols macro AC_CHECK_TYPE did not generate it.
Diffstat (limited to 'src/tests/common_tev.c')
0 files changed, 0 insertions, 0 deletions
ref='#n115'>115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
/*
 *  Copyright (C) 2017  Thales Lima Oliveira <thales@ufu.br>
 *
 *  This program 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 2 of the License, or
 *  any later version.
 *
 *  This program 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 <https://www.gnu.org/licenses/>.
 */

#include "LoadForm.h"
#include "SwitchingForm.h"
#include "Load.h"

LoadForm::LoadForm(wxWindow* parent, Load* load) : LoadFormBase(parent)
{
    SetSize(GetBestSize());
    LoadElectricalData data = load->GetElectricalData();

    m_textCtrlName->SetValue(data.name);

    m_textCtrlActivePower->SetValue(Load::StringFromDouble(data.activePower));
    switch(data.activePowerUnit) {
        case UNIT_PU: {
            m_choiceActivePower->SetSelection(0);
        } break;
        case UNIT_W: {
            m_choiceActivePower->SetSelection(1);
        } break;
        case UNIT_kW: {
            m_choiceActivePower->SetSelection(2);
        } break;
        case UNIT_MW: {
            m_choiceActivePower->SetSelection(3);
        } break;
        default:
            break;
    }

    m_textCtrlReactivePower->SetValue(Load::StringFromDouble(data.reactivePower));
    switch(data.reactivePowerUnit) {
        case UNIT_PU: {
            m_choiceReactivePower->SetSelection(0);
        } break;
        case UNIT_VAr: {
            m_choiceReactivePower->SetSelection(1);
        } break;
        case UNIT_kVAr: {
            m_choiceReactivePower->SetSelection(2);
        } break;
        case UNIT_MVAr: {
            m_choiceReactivePower->SetSelection(3);
        } break;
        default:
            break;
    }

    switch(data.loadType) {
        case CONST_POWER: {
            m_choiceType->SetSelection(0);
        } break;
        case CONST_IMPEDANCE: {
            m_choiceType->SetSelection(1);
        } break;
    }

    m_checkBoxPlotData->SetValue(data.plotLoad);

    m_checkBoxUseCompLoad->SetValue(data.useCompLoad);

    m_textCtrlActivePowerImp->SetValue(Element::StringFromDouble(data.constImpedanceActive));
    m_textCtrlActivePowerCur->SetValue(Element::StringFromDouble(data.constCurrentActive));
    m_textCtrlActivePowerPow->SetValue(Element::StringFromDouble(data.constPowerActive));
    m_textCtrlReactivePowerImp->SetValue(Element::StringFromDouble(data.constImpedanceReactive));
    m_textCtrlReactivePowerCur->SetValue(Element::StringFromDouble(data.constCurrentReactive));
    m_textCtrlReactivePowerPow->SetValue(Element::StringFromDouble(data.constPowerReactive));

    m_parent = parent;
    m_load = load;
    
    UpdateZIPLoadFieldStatus();
}

LoadForm::~LoadForm() {}
void LoadForm::OnOnButtonClick(wxCommandEvent& event)
{
    if(ValidateData()) EndModal(wxID_OK);
}

void LoadForm::OnStabilityButtonClick(wxCommandEvent& event)
{
    if(ValidateData()) {
        SwitchingForm swForm(m_parent, m_load);
        swForm.SetTitle(_("Load: Switching"));
        swForm.ShowModal();
        EndModal(wxID_OK);
    }
}

bool LoadForm::ValidateData()
{
    LoadElectricalData data;

    data.name = m_textCtrlName->GetValue();

    if(!m_load->DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
                                 _("Value entered incorrectly in the field \"Active power\".")))
        return false;
    switch(m_choiceActivePower->GetSelection()) {
        case 0: {
            data.activePowerUnit = UNIT_PU;
        } break;
        case 1: {
            data.activePowerUnit = UNIT_W;
        } break;
        case 2: {
            data.activePowerUnit = UNIT_kW;
        } break;
        case 3: {
            data.activePowerUnit = UNIT_MW;
        } break;
    }

    if(!m_load->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
                                 _("Value entered incorrectly in the field \"Reactive power\".")))
        return false;
    switch(m_choiceReactivePower->GetSelection()) {
        case 0: {
            data.reactivePowerUnit = UNIT_PU;
        } break;
        case 1: {
            data.reactivePowerUnit = UNIT_VAr;
        } break;
        case 2: {
            data.reactivePowerUnit = UNIT_kVAr;
        } break;
        case 3: {
            data.reactivePowerUnit = UNIT_MVAr;
        } break;
    }

    switch(m_choiceType->GetSelection()) {
        case 0: {
            data.loadType = CONST_POWER;
        } break;
        case 1: {
            data.loadType = CONST_IMPEDANCE;
        } break;
    }

    data.plotLoad = m_checkBoxPlotData->GetValue();

    data.useCompLoad = m_checkBoxUseCompLoad->GetValue();

    if(!Element::DoubleFromString(
           this, m_textCtrlActivePowerImp->GetValue(), data.constImpedanceActive,
           _("Value entered incorrectly in the field \"Constant impedance portion of active power\".")))
        return false;
    if(!Element::DoubleFromString(
           this, m_textCtrlActivePowerCur->GetValue(), data.constCurrentActive,
           _("Value entered incorrectly in the field \"Constant current portion of active power\".")))
        return false;
    if(!Element::DoubleFromString(
           this, m_textCtrlActivePowerPow->GetValue(), data.constPowerActive,
           _("Value entered incorrectly in the field \"Constant power portion of active power\".")))
        return false;
    if(!Element::DoubleFromString(
           this, m_textCtrlReactivePowerImp->GetValue(), data.constImpedanceReactive,
           _("Value entered incorrectly in the field \"Constant impedance portion of reactive power\".")))
        return false;
    if(!Element::DoubleFromString(
           this, m_textCtrlReactivePowerCur->GetValue(), data.constCurrentReactive,
           _("Value entered incorrectly in the field \"Constant current portion of reactive power\".")))
        return false;
    if(!Element::DoubleFromString(
           this, m_textCtrlReactivePowerPow->GetValue(), data.constPowerReactive,
           _("Value entered incorrectly in the field \"Constant power portion of reactive power\".")))
        return false;

    double sum = data.constImpedanceActive + data.constCurrentActive + data.constPowerActive;
    if(sum > 100.01 || sum < 99.99) {
        wxMessageDialog msgDialog(this, _("The sum of active power load composition must be 100%."), _("Error"),
                                  wxOK | wxCENTRE | wxICON_ERROR);
        msgDialog.ShowModal();
        return false;
    }
    sum = data.constImpedanceReactive + data.constCurrentReactive + data.constPowerReactive;
    if(sum > 100.01 || sum < 99.99) {
        wxMessageDialog msgDialog(this, _("The sum of reactive power load composition must be 100%."), _("Error"),
                                  wxOK | wxCENTRE | wxICON_ERROR);
        msgDialog.ShowModal();
        return false;
    }

    m_load->SetElectricalData(data);
    return true;
}

void LoadForm::UpdateZIPLoadFieldStatus()
{
    m_textCtrlActivePowerImp->Enable(m_checkBoxUseCompLoad->GetValue());
    m_textCtrlActivePowerCur->Enable(m_checkBoxUseCompLoad->GetValue());
    m_textCtrlActivePowerPow->Enable(m_checkBoxUseCompLoad->GetValue());
    m_textCtrlReactivePowerImp->Enable(m_checkBoxUseCompLoad->GetValue());
    m_textCtrlReactivePowerCur->Enable(m_checkBoxUseCompLoad->GetValue());
    m_textCtrlReactivePowerPow->Enable(m_checkBoxUseCompLoad->GetValue());
}