From 741817a25ebd770ce5f19982e3dfa7510de59964 Mon Sep 17 00:00:00 2001 From: Chris Stuart Date: Thu, 25 Aug 2016 16:38:21 +0100 Subject: [PATCH] Issue #12 Simple file choosing and reading. Next stages require use exceptions, which will stall work on this issue so that they can be introduced across the board. --- main.cpp | 2 ++ tds.cc | 53 +++++++++++++++++++++++++++++++++-------------------- tds.hh | 7 +++---- test.cxx | 22 ++++++++++++++++++---- test.fld | 19 ++++++++++++++----- test.h | 8 ++++++++ 6 files changed, 78 insertions(+), 33 deletions(-) diff --git a/main.cpp b/main.cpp index 629b76e..4c77546 100644 --- a/main.cpp +++ b/main.cpp @@ -47,6 +47,8 @@ int main(int nArg, char** vArg){ } else { tds_r = new tds_run(); tds_r->read_run_file(cl[2].arg); + tds_r->process_plugins(); + tds_r->initialise(); tds_r->make_analysis(); return 0; } diff --git a/tds.cc b/tds.cc index 4ee6348..4bb7d99 100644 --- a/tds.cc +++ b/tds.cc @@ -392,6 +392,10 @@ void tds_run::set_units_from_file(const char* units_file_address_) { } void tds_run::initialise() { + + int progress; + uint64 now; + uint64 checkmark = GetTimeMs64(); // Before we can read in any data, we should look for // any settings about (measurement) units we can find @@ -785,6 +789,9 @@ void tds_run::initialise() { settings.tracking_list->push_back(i); } } + now = GetTimeMs64(); + progress = (now - checkmark)/1000; + std::cout << "Initialisation took " << progress << " seconds." << std::endl; } void tds_run::process_plugins() { @@ -846,7 +853,7 @@ void tds_run::read_run_file(std::string run_file_name) { settings.tracking_list = new std::vector(); - std::cout << "Run file reading not yet fully implemented!" << std::endl; + //Run file reading not yet fully implemented! // most importantly, the checks to make sure that the user has // specified all the required fields in their .run file before @@ -1028,9 +1035,6 @@ void tds_run::read_run_file(std::string run_file_name) { } line_processing.clear(); } - - // Process the plugins, which have been stored as a list of string plugin names and file names - process_plugins(); // Set the number of simulation steps from the step size and simulation length steps(ceil(settings.simulation_length/settings.delta_t)); @@ -1040,11 +1044,6 @@ void tds_run::read_run_file(std::string run_file_name) { now = GetTimeMs64(); progress = (now - checkmark)/1000; std::cout << "Instructions read in " << progress << " seconds. Initialising..." << std::endl; - checkmark = now; - this->initialise(); - now = GetTimeMs64(); - progress = (now - checkmark)/1000; - std::cout << "Initialisation took " << progress << " seconds." << std::endl; @@ -1148,10 +1147,14 @@ void tds_run::interrupt_post_simulation() { tds_display::tds_display(UserInterface *gui):GUI_(gui){ GUI_->txdsp_run_file_name->buffer(FRunFileName); - // GUI_->RootfileComment->buffer(FRootfileComments); - // GUI_->TimelineComment->buffer(TimelineComment); - // GUI_->RootfileName->buffer(FRootfileName); - FRunFileName.text("default.run\n\n\n\n oaisdnoaisdn\no\tndsoinsdo\n\n\n oaisdnoaisdn\no\tndsoinsdo\n\n\n oaisdnoaisdn\no\tndsoinsdonioin"); + GUI_->txedt_run_file_contents->buffer(FRunFileContents); + std::string run_file_name = "example.run"; + FRunFileName.text(run_file_name.c_str()); + //std::ifstream run_file_(run_file_name); + //char defaultRunContents[8192]; + //run_file_.read(defaultRunContents,8192); + //FRunFileContents.text(defaultRunContents); + FRunFileContents.loadfile(FRunFileName.text()); // FRootfileComments.text("\n \n \t Choose a file"); } @@ -1159,13 +1162,15 @@ tds_display::~tds_display(){ // GUI_->plotH->clear(); } -void tds_display::dialog_open(){ - const char *filePtr=fl_file_chooser("Input File",NULL,"",0); - if(filePtr){ - std::cout<<"open"<btn_open_run_file) { + open_run_file_dialog(); + std::cout << "\tOpen run file..." << std::endl; + } +} +bool tds_display::previous_settings_were_saved() { + std::cout << "Skipped checking settings were saved." << std::endl; + return true; } diff --git a/tds.hh b/tds.hh index dae2f8b..9407594 100644 --- a/tds.hh +++ b/tds.hh @@ -265,17 +265,16 @@ private: std::vector text_; const char *filename_; Fl_Text_Buffer FRunFileName; - Fl_Text_Buffer FRootfileComments; - Fl_Text_Buffer FRootfileName; - Fl_Text_Buffer TimelineComment; + Fl_Text_Buffer FRunFileContents; std::string e_info_,tl_info_; protected: - void dialog_open(); + void open_run_file_dialog(); void load_event(); void load_section(int chnum); void load_section(unsigned int c, int chnum); void resize_plot(int section); void makeZoomBox(selection sel,int event,int section); + bool previous_settings_were_saved(); public: tds_display(UserInterface *gui); virtual ~tds_display(); diff --git a/test.cxx b/test.cxx index a8b6580..9a3abd0 100644 --- a/test.cxx +++ b/test.cxx @@ -5,17 +5,31 @@ void userAction(Fl_Widget* target); void userAction(selection sel, Ca_Canvas* sender); void reduce_all(); +void UserInterface::cb_btn_open_run_file_i(Fl_Button*, void*) { + userAction(btn_open_run_file); +} +void UserInterface::cb_btn_open_run_file(Fl_Button* o, void* v) { + ((UserInterface*)(o->parent()->parent()->user_data()))->cb_btn_open_run_file_i(o,v); +} + Fl_Double_Window* UserInterface::make_window() { { main_window = new Fl_Double_Window(900, 510, "Tritium Diffusion Software - v0.1 - Chris Stuart"); main_window->user_data((void*)(this)); - { grp_run_file = new Fl_Group(25, 102, 366, 326); + { grp_run_file = new Fl_Group(12, 99, 505, 404); grp_run_file->box(FL_DOWN_BOX); - { txdsp_run_file_name = new Fl_Text_Display(30, 126, 351, 95, "Current run file:"); + { txdsp_run_file_name = new Fl_Text_Display(17, 123, 390, 23, "Current run file:"); txdsp_run_file_name->box(FL_UP_FRAME); - txdsp_run_file_name->align(Fl_Align(FL_ALIGN_CENTER)); - txdsp_run_file_name->scrollbar_align(FL_ALIGN_RIGHT); + txdsp_run_file_name->align(Fl_Align(FL_ALIGN_TOP_LEFT)); + txdsp_run_file_name->scrollbar_align(0); txdsp_run_file_name->scroll(0,1); } // Fl_Text_Display* txdsp_run_file_name + { txedt_run_file_contents = new Fl_Text_Editor(17, 152, 495, 345); + txedt_run_file_contents->box(FL_DOWN_BOX); + txedt_run_file_contents->cursor_style(Fl_Text_Display::NORMAL_CURSOR); + } // Fl_Text_Editor* txedt_run_file_contents + { btn_open_run_file = new Fl_Button(412, 122, 100, 25, "Open..."); + btn_open_run_file->callback((Fl_Callback*)cb_btn_open_run_file); + } // Fl_Button* btn_open_run_file grp_run_file->end(); } // Fl_Group* grp_run_file main_window->size_range(900, 510, 900, 510); diff --git a/test.fld b/test.fld index 8dfadb6..e0a9770 100644 --- a/test.fld +++ b/test.fld @@ -35,17 +35,26 @@ class UserInterface {open } { Fl_Window main_window { label {Tritium Diffusion Software - v0.1 - Chris Stuart} open - xywh {1018 385 900 510} type Double size_range {900 510 900 510} visible + xywh {776 364 900 510} type Double size_range {900 510 900 510} visible } { Fl_Group grp_run_file {open - xywh {25 102 366 326} box DOWN_BOX + xywh {12 99 505 404} box DOWN_BOX } { Fl_Text_Display txdsp_run_file_name { - label {Current run file:} selected - xywh {30 126 351 95} box UP_FRAME align 0 - code0 {txdsp_run_file_name->scrollbar_align(FL_ALIGN_RIGHT);} + label {Current run file:} + xywh {17 123 390 23} box UP_FRAME align 5 + code0 {txdsp_run_file_name->scrollbar_align(0);} code1 {txdsp_run_file_name->scroll(0,1);} } + Fl_Text_Editor txedt_run_file_contents {selected + xywh {17 152 495 345} box DOWN_BOX + code0 {txedt_run_file_contents->cursor_style(Fl_Text_Display::NORMAL_CURSOR);} + } + Fl_Button btn_open_run_file { + label {Open...} + callback {userAction(btn_open_run_file);} + xywh {412 122 100 25} + } } } } diff --git a/test.h b/test.h index 3ad4e59..a8779dd 100644 --- a/test.h +++ b/test.h @@ -15,6 +15,8 @@ extern void reduce_all(); #include #include #include +#include +#include class UserInterface { public: @@ -22,6 +24,12 @@ class UserInterface { Fl_Double_Window *main_window; Fl_Group *grp_run_file; Fl_Text_Display *txdsp_run_file_name; + Fl_Text_Editor *txedt_run_file_contents; + Fl_Button *btn_open_run_file; +private: + inline void cb_btn_open_run_file_i(Fl_Button*, void*); + static void cb_btn_open_run_file(Fl_Button*, void*); +public: void show(); }; #endif