Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions src/casewin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,19 @@ bool CaseWindow::RunSSCBaseCase(wxString& fn, bool silent, wxString* messages)
}


void CaseWindow::ExportCashflowExcel()
{
// run base case automatically
if (!RunBaseCase())
{
wxMessageBox("Base case simulation did not succeed. Please check your inputs before creating a report");
return;
}
UpdateResults();
m_baseCaseResults->Export(EXP_CASHFLOW, EXP_SEND_EXCEL);
}


void CaseWindow::UpdateResults()
{
m_baseCaseResults->Setup( &m_case->BaseCase() );
Expand Down
2 changes: 2 additions & 0 deletions src/casewin.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class CaseWindow : public wxSplitterWindow, CaseEventListener
bool RunBaseCase( bool silent = false, wxString *messages = 0 );
void UpdateResults();

void ExportCashflowExcel();

bool RunSSCBaseCase(wxString& fn, bool silent = false, wxString* messages = 0);

bool GenerateReport(
Expand Down
1 change: 1 addition & 0 deletions src/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include "macro.h"
#include "invoke.h"

class macro_vm : public lk::vm
{
Expand Down
25 changes: 15 additions & 10 deletions src/reports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,11 +2255,16 @@ void SamReportScriptObject::Render( wxPageOutputDevice &dv )
env.register_funcs( lk::stdlib_math() );
env.register_funcs( lk::stdlib_wxui() );

wxStopWatch sw;
lk::eval e( tree, &env );
if ( !e.run() )
for (size_t i=0;i<e.error_count();i++)
errors += e.get_error(i) + "\n";
try {
wxStopWatch sw;
lk::eval e(tree, &env);
if (!e.run())
for (size_t i = 0; i < e.error_count(); i++)
errors += e.get_error(i) + "\n";
}
catch (std::exception e) {
wxMessageBox(e.what());
}
}

int i=0;
Expand Down Expand Up @@ -2559,7 +2564,7 @@ void SamReportScriptObject::RenderTable( const matrix_t<wxString> &tab )
float xpos = tab_x;
for (int c=0;c<(int)tab.ncols();c++)
{
int align = (r==0) ? m_headerAlign : m_cellAlign;
int align = (r<m_headerLines) ? m_headerAlign : m_cellAlign;
switch( align )
{
case wxLEFT:
Expand Down Expand Up @@ -2602,11 +2607,11 @@ void SamReportScriptObject::RenderTable( const matrix_t<wxString> &tab )
}

m_curDevice->Color( *wxBLACK );
if (m_headerLine && row_heights.size() > 0)
m_curDevice->Line( tab_x, tab_y+row_heights[0],
tab_x+tab_width, tab_y+row_heights[0] );
if (m_headerLine && row_heights.size() > 0 )
m_curDevice->Line( tab_x, tab_y+m_headerLines*row_heights[0],
tab_x+tab_width, tab_y+ m_headerLines * row_heights[0] );
float ypos_total_lines = tab_y+row_heights[0];
for (int r = 1; r < (int)tab.nrows(); r++) {
for (int r = m_headerLines - 1; r < (int)tab.nrows(); r++) {
ypos_total_lines += row_heights[r];
for (int b = 0; b < m_totalLines.size(); b++) {
if (r == m_totalLines[b] && r != (int)tab.nrows() - 1) {
Expand Down
3 changes: 2 additions & 1 deletion src/results.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class ResultsViewer : public wxMetroNotebook
TabularBrowser *GetTabularBrowser() { return m_tables; }
wxString GetCurrentContext() const;

void Export(int data, int mechanism);

private:
Simulation *m_sim = nullptr;

Expand Down Expand Up @@ -227,7 +229,6 @@ class ResultsViewer : public wxMetroNotebook

void AddDataSet( wxDVTimeSeriesDataSet *ds, const wxString &group = wxEmptyString, bool update_ui = true );
void RemoveAllDataSets();
void Export(int data, int mechanism);
void GetExportData(int data, matrix_t<wxString> &table);
void ExportEqnExcel();

Expand Down
11 changes: 11 additions & 0 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ void fcall_show_page(lk::invoke_t &cxt)
else cxt.error("no active case");
}

void fcall_export_cashflow_excel(lk::invoke_t& cxt)
{
LK_DOC("export_cashflow_excel", "Exports the cashflow for the active case to Excel (Windows only)", "( string:page name ):boolean");
Case* active_case = CurrentCase();
if (CaseWindow* case_window = SamApp::Window()->GetCaseWindow(active_case)) {
case_window->ExportCashflowExcel();
}
else cxt.error("no active case");
}

void fcall_widgetpos( lk::invoke_t &cxt )
{
LK_DOC("widgetpos", "Get geometry in pixels in toplevel coordinates of the widget associated with the specified variable.", "(string:name):array" );
Expand Down Expand Up @@ -659,6 +669,7 @@ lk::fcall_t *sam_functions() {
fcall_simulate,
fcall_simulate_ssc_tests,
fcall_show_page,
fcall_export_cashflow_excel,
fcall_widgetpos,
fcall_focusto,
fcall_configuration,
Expand Down
Loading