Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/wex/dview/dvfilereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ class wxDVFileReader {
public:
static void ReadDataFromCSV(wxDVPlotCtrl *plotWin, const wxString &filename, wxChar separator = ',');

// ipUnits: -1 = ask user (dialog), 0 = SI, 1 = IP
static bool
FastRead(wxDVPlotCtrl *plotWin, const wxString &filename, int prealloc_data = 8760, int prealloc_lnchars = 1024);
FastRead(wxDVPlotCtrl *plotWin, const wxString &filename, int prealloc_data = 8760, int prealloc_lnchars = 1024,
int ipUnits = -1);

static bool Read8760WFLines(std::vector<wxDVArrayDataSet *> &dataSets, FILE *infile, int wfType);

static bool ReadWeatherFile(wxDVPlotCtrl *plotWin, const wxString &filename);

static bool ReadSQLFile(wxDVPlotCtrl *plotWin, const wxString &filename);
// ipUnits: -1 = ask user (dialog), 0 = SI, 1 = IP
static bool ReadSQLFile(wxDVPlotCtrl *plotWin, const wxString &filename, int ipUnits = -1);

static bool IsNumeric(wxString stringToCheck);

Expand Down
14 changes: 10 additions & 4 deletions src/dview/dvfilereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,15 @@ static bool ReadWeatherFileLine(FILE *fp, int type,
}

bool
wxDVFileReader::FastRead(wxDVPlotCtrl *plotWin, const wxString &filename, int prealloc_data, int prealloc_lnchars) {
wxDVFileReader::FastRead(wxDVPlotCtrl *plotWin, const wxString &filename, int prealloc_data, int prealloc_lnchars,
int ipUnits) {
wxString fExtension = filename.Right(3);
if (fExtension.CmpNoCase("tm2") == 0 ||
fExtension.CmpNoCase("epw") == 0 ||
fExtension.CmpNoCase("smw") == 0) {
return ReadWeatherFile(plotWin, filename);
} else if (fExtension.CmpNoCase("sql") == 0) {
return ReadSQLFile(plotWin, filename);
return ReadSQLFile(plotWin, filename, ipUnits);
}

wxStopWatch sw;
Expand Down Expand Up @@ -933,7 +934,7 @@ bool wxDVFileReader::Read8760WFLines(std::vector<wxDVArrayDataSet *> &dataSets,
return true;
}

bool wxDVFileReader::ReadSQLFile(wxDVPlotCtrl *plotWin, const wxString &filename) {
bool wxDVFileReader::ReadSQLFile(wxDVPlotCtrl *plotWin, const wxString &filename, int ipUnits) {
wxFileName fileName(filename);

if (!fileName.IsFileReadable()) {
Expand All @@ -945,8 +946,13 @@ bool wxDVFileReader::ReadSQLFile(wxDVPlotCtrl *plotWin, const wxString &filename
int success = sqlite3_open_v2(filename.c_str(), &db, SQLITE_OPEN_READONLY | SQLITE_OPEN_EXCLUSIVE, nullptr);

if (success == SQLITE_OK) {
int convertUnits = wxMessageBox(wxT("Would you like to display your Energy+ data in IP units?."),
int convertUnits;
if (ipUnits < 0) {
convertUnits = wxMessageBox(wxT("Would you like to display your Energy+ data in IP units?."),
wxT("Units Conversion"), wxYES_NO);
} else {
convertUnits = ipUnits ? wxYES : wxNO;
}

wxStopWatch sw;
sw.Start();
Expand Down
15 changes: 12 additions & 3 deletions tools/dview/dview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class DViewFrame : public wxFrame {
Destroy();
}

bool Load(const wxArrayString &filenames) {
bool Load(const wxArrayString &filenames, int ipUnits = -1) {
bool FileExists = false;

wxBeginBusyCursor();
Expand All @@ -294,7 +294,7 @@ class DViewFrame : public wxFrame {
}

if (!FileExists) {
if (!wxDVFileReader::FastRead(mPlotCtrl, filenames[i])) {
if (!wxDVFileReader::FastRead(mPlotCtrl, filenames[i], 8760, 1024, ipUnits)) {
wxMessageBox(
wxT("The selected file is not of the correct format, is corrupt, no longer exists, or you do not have permission to open it."),
wxT("Error opening file."), wxICON_ERROR);
Expand Down Expand Up @@ -378,6 +378,7 @@ class DViewApp : public wxApp {

bool m_arg_showLog;
int m_arg_tab, m_arg_data;
int m_arg_ipUnits; // -1 = ask (dialog), 0 = SI, 1 = IP
double m_startHour, m_endHour;
wxArrayString m_variables;
wxArrayString m_arg_filenames;
Expand All @@ -399,7 +400,7 @@ class DViewApp : public wxApp {
DViewFrame *frame = new DViewFrame;

if (m_arg_filenames.Count() > 0)
frame->Load(m_arg_filenames);
frame->Load(m_arg_filenames, m_arg_ipUnits);

if (m_arg_tab != -1)
frame->GetPlot()->SelectTabIndex(m_arg_tab);
Expand Down Expand Up @@ -448,6 +449,8 @@ class DViewApp : public wxApp {
wxCMD_LINE_VAL_STRING);
parser.AddParam(wxT("files to load"), wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);
parser.AddSwitch(wxT(""), wxT("ip"), wxT("display Energy+ SQL data in IP units (skips dialog)"));
parser.AddSwitch(wxT(""), wxT("si"), wxT("display Energy+ SQL data in SI units (skips dialog)"));
}

bool OnCmdLineParsed(wxCmdLineParser &parser) {
Expand All @@ -464,6 +467,12 @@ class DViewApp : public wxApp {
else
m_arg_showLog = false;

m_arg_ipUnits = -1;
if (parser.Found(wxT("ip")))
m_arg_ipUnits = 1;
else if (parser.Found(wxT("si")))
m_arg_ipUnits = 0;

m_arg_tab = -1;
if (parser.Found(wxT("t"), &tabNumber) && tabNumber >= 0)
m_arg_tab = tabNumber;
Expand Down