Skip to content

Commit

Permalink
Ignore last chart if this have no series
Browse files Browse the repository at this point in the history
PageDown when last chart is active is will create a new chart. This may be empty (no series)
  • Loading branch information
tskille committed Oct 30, 2022
1 parent ba8a5b0 commit ab296fe
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 19 deletions.
23 changes: 7 additions & 16 deletions appl/smry_appl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,21 +1085,21 @@ void SmryAppl::adjust_yaxis_props(SmryYaxis* axis, double& min_data, double& max


template <typename T>
bool SmryAppl::reopen_loader(int n, std::unique_ptr<T>& smry, const std::filesystem::path& smryfile)
bool SmryAppl::reopen_loader(int n, std::unique_ptr<T>& smry)
{
std::unique_ptr<T> smry_tmp;

try {
smry_tmp = std::make_unique<T> ( m_smry_files[n] );
} catch (...) {
std::string message = "Error with reopen loader, failed when opening summary file " + smryfile.string();
std::string message = "Error with reopen loader, failed when opening summary file " + m_smry_files[n].string();
throw std::runtime_error(message);
}

auto nstep_tmp = smry_tmp->numberOfTimeSteps();
auto nstep = smry->numberOfTimeSteps();

auto ftime = std::filesystem::last_write_time ( smryfile );
auto ftime = std::filesystem::last_write_time ( m_smry_files[n] );
bool updated = false;

if ( ftime > file_stamp_vector[n] ){
Expand Down Expand Up @@ -1167,9 +1167,9 @@ bool SmryAppl::reload_and_update_charts()
if (std::filesystem::exists(m_smry_files[n] )) {

if (m_file_type[n] == FileType::SMSPEC)
updated_list[n] = reopen_loader( n, m_esmry_loader[n], m_smry_files[n] );
updated_list[n] = reopen_loader( n, m_esmry_loader[n] );
else if (m_file_type[n] == FileType::ESMRY)
updated_list[n] = reopen_loader( n, m_ext_esmry_loader[n], m_smry_files[n] );
updated_list[n] = reopen_loader( n, m_ext_esmry_loader[n] );

if (updated_list[n])
need_update = true;
Expand Down Expand Up @@ -1240,7 +1240,8 @@ bool SmryAppl::reload_and_update_charts()
}
}

// create new charts
if (series_properties[num_charts - 1].size() == 0)
num_charts --;

for ( int ind = 0; ind < num_charts; ind++ ) {

Expand Down Expand Up @@ -2545,17 +2546,7 @@ void SmryAppl::keyPressEvent ( QKeyEvent *event )
axisX[chart_ind]->setRange(std::get<0>(current_xrange), std::get<1>(current_xrange));


//std::cout << "This must be updated \n";

auto min_max_range = axisX[chart_ind]->get_xrange();
/*
if (std::get<0>(min_max_range) < 0){
//axisX[chart_ind]->reset_range();
min_max_range = axisX[chart_ind]->get_xrange();
}
min_max_range = axisX[chart_ind]->get_xrange();
*/
update_all_yaxis(min_max_range, chart_ind);
}

Expand Down
2 changes: 1 addition & 1 deletion appl/smry_appl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private slots:
void handle_delete_series();

template <typename T>
bool reopen_loader(int n, std::unique_ptr<T>& smry, const std::filesystem::path& smryfile);
bool reopen_loader(int n, std::unique_ptr<T>& smry);

bool has_smry_vect(int smry_ind, const std::string& keystr);
const std::vector<float>& get_smry_vect(int case_ind, std::string& keystr);
Expand Down
106 changes: 104 additions & 2 deletions tests/test_smry_appl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private slots:
void test_scale_axis_interactive_2();
void test_reload_1();
void test_reload_2();
void test_reload_3();
};

const int max_number_of_charts = 2000;
Expand Down Expand Up @@ -248,7 +249,6 @@ void smry_input(const std::vector<std::string>& fname_list,
smry_files.push_back( std::filesystem::path(fname_list[n]) );
}


void TestQsummary::test_show_markers()
{
SmryAppl::input_list_type input_charts;
Expand Down Expand Up @@ -1141,7 +1141,7 @@ void TestQsummary::test_reload_2()

xaxis = window.get_smry_xaxis(3);
QCOMPARE(chk_date_range(xaxis, 1997, 8, 2, 1999, 5, 17), true);
window.grab().save("tmp2.png");
//window.grab().save("tmp2.png");

d1.setDate(2001,6,1);
until_dt.setDate(d1);
Expand Down Expand Up @@ -1175,6 +1175,108 @@ void TestQsummary::test_reload_2()
//window.grab().save("tmp6.p(ng");
}


void TestQsummary::test_reload_3()
{
Opm::EclIO::EclFile esmry1("../tests/smry_files/NORNE_S1.ESMRY");
Opm::EclIO::ExtESmry smry1("../tests/smry_files/NORNE_S1.ESMRY");

Opm::EclIO::EclFile esmry2("../tests/smry_files/NORNE_S2.ESMRY");
Opm::EclIO::ExtESmry smry2("../tests/smry_files/NORNE_S2.ESMRY");

QDate d1;
QTime t1;

d1.setDate(2000,1,1);
t1.setHMS(0,0,0,0);

QDateTime until_dt;
until_dt.setTimeSpec(Qt::UTC);

until_dt.setDate(d1);
until_dt.setTime(t1);

// make esmry file from NORNE_S1.ESMRY with data from sos until 2000-01-01
make_esmry_from_esmry(esmry1, smry1, "TEST1.ESMRY", until_dt);

d1.setDate(1999,1,1);
until_dt.setDate(d1);

// make esmry file from NORNE_S2.ESMRY with data from sos until 1999-01-01
make_esmry_from_esmry(esmry2, smry2, "TEST2.ESMRY", until_dt);

// set up application, 2 summary files, make one chart with FOPR, xrange not set.
SmryAppl::input_list_type input_charts;
SmryAppl::loader_list_type loaders;

int num_files = 2;

std::vector<std::string> fname_list;
std::vector<FileType> file_type;

file_type.resize(num_files);
fname_list.resize(num_files);

fname_list[0] = "TEST1.ESMRY";
fname_list[1] = "TEST2.ESMRY";

file_type = { FileType::ESMRY, FileType::ESMRY };

QsumCMDF cmdfile("../tests/cmd_files/test4b.txt", num_files, "");

cmdfile.make_charts_from_cmd(input_charts, "");

std::unordered_map<int, std::unique_ptr<Opm::EclIO::ESmry>> esmry_loader;
std::unordered_map<int, std::unique_ptr<Opm::EclIO::ExtESmry>> ext_smry_loader;
std::vector<std::filesystem::path> smry_files;

// set up loaders and smry file system paths
smry_input(fname_list, file_type, esmry_loader, ext_smry_loader, smry_files);

// derived summary object for smryAppl
std::unique_ptr<DerivedSmry> derived_smry;
derived_smry = std::make_unique<DerivedSmry>(cmdfile, file_type, esmry_loader, ext_smry_loader);

// make loaders for smryAppl
loaders = std::make_tuple(smry_files, file_type, std::move(esmry_loader), std::move(ext_smry_loader));


SmryAppl window(fname_list, loaders, input_charts, derived_smry);

window.resize(1400, 700);

window.grab();

QCOMPARE(window.number_of_charts(), 4);

QTest::keyEvent(QTest::Click, &window, Qt::Key_PageDown);
QTest::keyEvent(QTest::Click, &window, Qt::Key_PageDown);
QTest::keyEvent(QTest::Click, &window, Qt::Key_PageDown);
QTest::keyEvent(QTest::Click, &window, Qt::Key_PageDown);

QTest::keyEvent(QTest::Click, &window, Qt::Key_PageUp);

//window.grab().save("tmp1.png");

d1.setDate(1999,5,17);
until_dt.setDate(d1);

// rewrite of TEST2.ESMRY, now with data until 1999-05-10
make_esmry_from_esmry(esmry2, smry2, "TEST2.ESMRY", until_dt);

QTest::keyEvent(QTest::Click, &window, Qt::Key_R, Qt::ControlModifier | Qt::ShiftModifier);

std::filesystem::path testf1(fname_list[0]);
std::filesystem::path testf2(fname_list[1]);

if (std::filesystem::exists(testf1))
std::filesystem::remove(testf1);

if (std::filesystem::exists(testf2))
std::filesystem::remove(testf2);
}


QTEST_MAIN(TestQsummary)

#include "test_smry_appl.moc"

0 comments on commit ab296fe

Please sign in to comment.