Skip to content

Commit

Permalink
Issue #12 Simple file choosing and reading. Next stages require use e…
Browse files Browse the repository at this point in the history
…xceptions, which will stall work on this issue so that they can be introduced across the board.
  • Loading branch information
Chris Stuart committed Aug 25, 2016
1 parent 628b0b3 commit 741817a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 33 deletions.
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
53 changes: 33 additions & 20 deletions tds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -846,7 +853,7 @@ void tds_run::read_run_file(std::string run_file_name) {
settings.tracking_list = new std::vector<int>();


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
Expand Down Expand Up @@ -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));
Expand All @@ -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;



Expand Down Expand Up @@ -1148,24 +1147,30 @@ 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");
}

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"<<std::endl;
filename(filePtr);
load_section(0);
FRootfileName.text(filePtr);
void tds_display::open_run_file_dialog(){
if (previous_settings_were_saved()) {
const char *filePtr=fl_file_chooser("Input File","Run Files (*.run)","",0);
if(filePtr){
filename(filePtr);
load_section(0);
FRunFileName.text(filePtr);
FRunFileContents.loadfile(FRunFileName.text());
}
}
}

Expand Down Expand Up @@ -1203,6 +1208,14 @@ void tds_display::action(selection sel, Fl_Widget *sender){

void tds_display::action(Fl_Widget *sender){
std::cout<<"display action"<<std::endl;
if (sender == GUI_->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;
}


Expand Down
7 changes: 3 additions & 4 deletions tds.hh
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,16 @@ private:
std::vector<std::string> 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();
Expand Down
22 changes: 18 additions & 4 deletions test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 14 additions & 5 deletions test.fld
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ extern void reduce_all();
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/Fl_Button.H>

class UserInterface {
public:
Fl_Double_Window* make_window();
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

0 comments on commit 741817a

Please sign in to comment.