diff --git a/src/main.cpp b/src/main.cpp index 6f5200354..5ac862eeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,18 +32,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include //#include +#include #include #include #include -#include - -#if defined(__WXMSW__)||defined(__WXOSX__) -#include -#else -#include // for linux - avoid webkitgtk dependencies -#endif - +#include #include #include #include @@ -53,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include #include @@ -66,7 +59,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - #include "../resource/menu.cpng" #include "../resource/notes_white.cpng" @@ -106,13 +98,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static PythonConfig pythonConfig; - enum { __idFirst = wxID_HIGHEST+592, - ID_MAIN_MENU, ID_CASE_TABS, ID_PAGE_NOTES, - ID_CASE_CREATE, ID_RUN_ALL_CASES, ID_SAVE_HOURLY, + ID_MAIN_MENU, + ID_CASE_TABS, + ID_PAGE_NOTES, + ID_RELEASE_NOTES, + ID_BROWSER, + ID_CASE_CREATE, + ID_RUN_ALL_CASES, + ID_SAVE_HOURLY, ID_IMPORT_CASES, - ID_NEW_SCRIPT, ID_OPEN_SCRIPT, ID_BROWSE_INPUTS, + ID_NEW_SCRIPT, + ID_OPEN_SCRIPT, + ID_BROWSE_INPUTS, __idCaseMenuFirst, ID_CASE_CONFIG, ID_CASE_RENAME, @@ -137,8 +136,6 @@ enum { __idFirst = wxID_HIGHEST+592, BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_CLOSE( MainWindow::OnClose ) - EVT_MENU( wxID_ABOUT, MainWindow::OnCommand ) - EVT_MENU( wxID_HELP, MainWindow::OnCommand ) EVT_MENU( ID_SAVE_HOURLY, MainWindow::OnCommand ) EVT_MENU( ID_IMPORT_CASES, MainWindow::OnCommand ) EVT_MENU( wxID_NEW, MainWindow::OnCommand ) @@ -156,6 +153,7 @@ BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_BUTTON(ID_MAIN_MENU, MainWindow::OnCommand) EVT_LISTBOX( ID_CASE_TABS, MainWindow::OnCaseTabChange ) EVT_BUTTON( ID_CASE_TABS, MainWindow::OnCaseTabButton ) + EVT_BUTTON(wxID_ABOUT, MainWindow::OnCommand) EVT_BUTTON( wxID_HELP, MainWindow::OnCommand ) EVT_BUTTON( ID_PAGE_NOTES, MainWindow::OnCommand ) EVT_MENU_RANGE( __idCaseMenuFirst, __idCaseMenuLast, MainWindow::OnCaseMenu ) @@ -238,7 +236,8 @@ MainWindow::MainWindow() tools->Add( metbut = new wxMetroButton( m_caseTabPanel, ID_PAGE_NOTES, wxEmptyString, wxBITMAP_PNG_FROM_DATA( notes_white ), wxDefaultPosition, wxDefaultSize), 0, wxALL|wxEXPAND, 0 ); metbut->SetToolTip( "Add a page note" ); - tools->Add( new wxMetroButton( m_caseTabPanel, wxID_HELP, "Help",/* wxBITMAP_PNG_FROM_DATA(qmark) */ wxNullBitmap, wxDefaultPosition, wxDefaultSize), 0, wxALL|wxEXPAND, 0 ); + tools->Add(new wxMetroButton(m_caseTabPanel, wxID_ABOUT, "About",wxNullBitmap, wxDefaultPosition, wxDefaultSize), 0, wxALL | wxEXPAND, 0); + tools->Add( new wxMetroButton( m_caseTabPanel, wxID_HELP, "Help",/*wxBITMAP_PNG_FROM_DATA(qmark)*/ wxNullBitmap, wxDefaultPosition, wxDefaultSize), 0, wxALL | wxEXPAND, 0); m_caseNotebook = new wxSimplebook( m_caseTabPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE ); @@ -2456,67 +2455,141 @@ wxArrayString SamApp::RecentFiles() return files; } -void SamApp::ShowHelp( const wxString &context ) +class HelpWin : public wxFrame { - wxString url; - if ( context.Left(1) == ":" ) - url = context; // for things like :about, etc - else + wxHtmlWindow* m_htmlView; + + wxString m_aboutHtml; +public: + HelpWin(wxWindow* parent) + : wxFrame(parent, wxID_ANY, "About System Advisor Model (SAM)", wxDefaultPosition, wxScaleSize(1000, 600)) { - wxFileName fn( SamApp::GetRuntimePath() + "/help/html/" ); - fn.MakeAbsolute(); - url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + "index.html"; -#ifdef __WXGTK__ - if ( ! context.IsEmpty() ) - url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + context + ".html"; - wxLaunchDefaultBrowser( url ); - return; -#else - if ( ! context.IsEmpty() ) - url += "?" + context + ".html"; + CreateAboutHtml(); + +#ifdef __WXMSW__ + SetIcon(wxICON(appicon)); #endif + + SetBackgroundColour(wxMetroTheme::Colour(wxMT_FOREGROUND)); + + m_htmlView = new wxHtmlWindow(this, ID_BROWSER); + m_htmlView->SetPage(m_aboutHtml); + + wxBoxSizer* tools = new wxBoxSizer(wxHORIZONTAL); + tools->AddStretchSpacer(); + tools->Add( new wxMetroButton( this, ID_RELEASE_NOTES, "Open NLR release notes..." ), 0, wxALL|wxEXPAND, 0 ); + + wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add( tools, 0, wxALL|wxEXPAND, 0 ); + sizer->Add(m_htmlView, 1, wxALL | wxEXPAND, 0); + SetSizer(sizer); } - wxWindow *modal_active = 0; - wxWindow *nonmodal_tlw = 0; - for( wxWindowList::iterator wl = wxTopLevelWindows.begin(); - wl != wxTopLevelWindows.end(); - ++wl ) + void CreateAboutHtml() { - wxTopLevelWindow *tlw = dynamic_cast( *wl ); - wxDialog *dia = dynamic_cast( *wl ); - - if ( tlw != 0 && (dia == 0 || !dia->IsModal()) ) - nonmodal_tlw = tlw; + m_aboutHtml = SamApp::AboutSAM(); + } - if ( dia != 0 && dia->IsActive() && dia->IsModal() ) - modal_active = dia; + void LoadPage(wxString url) + { + if (url == ":about") + { + m_htmlView->SetPage(m_aboutHtml); + } + else if (url == ":release_notes") + { + wxLaunchDefaultBrowser(SamApp::WebApi("release_notes")); + } + else + { + wxLaunchDefaultBrowser(url); + } } - // try several different parent windows for the help window - // if possible, use the SAM main window - // otherwise, choose any top level window that is not modal - // last resort, choose a currently modal dialog box - wxWindow *parent = SamApp::Window(); - if ( !parent ) parent = nonmodal_tlw; - if ( !parent ) parent = modal_active; - if ( modal_active && gs_helpWin != 0 && gs_helpWin->IsShown() ) + void OnClose(wxCloseEvent& evt) { - wxRect h_rect = gs_helpWin->GetRect(); + Hide(); + evt.Veto(); + } - if (gs_helpWin->Destroy()) + void OnCommand(wxCommandEvent& evt) + { + switch (evt.GetId()) { - gs_helpWin = new HelpWin( parent ); - gs_helpWin->SetSize(h_rect); + case ID_RELEASE_NOTES: + LoadPage(":release_notes"); + break; } } - else if ( 0 == gs_helpWin ) - gs_helpWin = new HelpWin( parent ); - gs_helpWin->Show( ); - gs_helpWin->LoadPage( url ); - gs_helpWin->Raise(); + DECLARE_EVENT_TABLE(); +}; + +BEGIN_EVENT_TABLE(HelpWin, wxFrame) +EVT_BUTTON(ID_RELEASE_NOTES, HelpWin::OnCommand) +EVT_CLOSE(HelpWin::OnClose) +END_EVENT_TABLE() + +class HelpWin; +static HelpWin* gs_helpWin = 0; + +void SamApp::ShowHelp( const wxString &help_context ) +{ + wxString url; + url = help_context; + if ( url.Left(1) == ":" ) // display things like :about in custom window + { + wxWindow *modal_active = 0; + wxWindow *nonmodal_tlw = 0; + for( wxWindowList::iterator wl = wxTopLevelWindows.begin(); wl != wxTopLevelWindows.end(); ++wl ) + { + wxTopLevelWindow *tlw = dynamic_cast( *wl ); + wxDialog *dia = dynamic_cast( *wl ); + + if ( tlw != 0 && (dia == 0 || !dia->IsModal()) ) + nonmodal_tlw = tlw; + + if ( dia != 0 && dia->IsActive() && dia->IsModal() ) + modal_active = dia; + } + + // try several different parent windows for the help window + // if possible, use the SAM main window + // otherwise, choose any top level window that is not modal + // last resort, choose a currently modal dialog box + wxWindow *parent = SamApp::Window(); + if ( !parent ) parent = nonmodal_tlw; + if ( !parent ) parent = modal_active; + + if ( modal_active && gs_helpWin != 0 && gs_helpWin->IsShown() ) + { + wxRect h_rect = gs_helpWin->GetRect(); + + if (gs_helpWin->Destroy()) + { + gs_helpWin = new HelpWin( parent ); + gs_helpWin->SetSize(h_rect); + } + } + else if ( 0 == gs_helpWin ) + gs_helpWin = new HelpWin( parent ); + + gs_helpWin->Show( ); + gs_helpWin->LoadPage( url ); + gs_helpWin->Raise(); + } + else // display help topics in default browser + { + wxFileName fn( SamApp::GetRuntimePath() + "/help/html/" ); + fn.MakeAbsolute(); + if ( help_context.IsEmpty() ) + url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + "index.html"; + else + url = "file:///" + fn.GetFullPath( wxPATH_NATIVE ) + help_context + ".html"; + wxLaunchDefaultBrowser( url ); + } + } int SamApp::RevisionNumber() diff --git a/src/main.h b/src/main.h index 50dfdf640..e86d54187 100644 --- a/src/main.h +++ b/src/main.h @@ -375,6 +375,7 @@ class SamApp : public wxApp static wxFileHistory &FileHistory(); static wxArrayString RecentFiles(); static void ShowHelp( const wxString &context = wxEmptyString ); + static wxString AboutSAM(); static wxString VersionStr( bool with_patches = false, bool short_style = false ); static int VersionMajor(); static int VersionMinor(); diff --git a/src/main_add.h b/src/main_add.h index 5d4005b65..0acfd0f0b 100644 --- a/src/main_add.h +++ b/src/main_add.h @@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "uiobjects.h" #include #include -#include #include #include @@ -67,7 +66,7 @@ void ShowIDEWindow() -enum { ID_BACK = wxID_HIGHEST + 439, ID_BROWSER, ID_HOME, ID_EMAIL_SUPPORT, ID_WEBSITE, ID_FORUM, ID_RELEASE_NOTES, ID_SCRIPT_REFERENCE }; +//enum { ID_BACK = wxID_HIGHEST + 439, ID_BROWSER, ID_HOME, ID_EMAIL_SUPPORT, ID_WEBSITE, ID_FORUM, ID_RELEASE_NOTES, ID_SCRIPT_REFERENCE }; static SamApp::ver releases[] = { @@ -469,202 +468,30 @@ extern void RegisterReportObjectTypes(); return true; } - - -class HelpWin : public wxFrame +wxString SamApp::AboutSAM() { -#if defined(__WXMSW__)||defined(__WXOSX__) - wxWebView *m_webView; -#else - wxHtmlWindow *m_htmlView; -#endif - - wxString m_aboutHtml; -public: - HelpWin( wxWindow *parent ) - : wxFrame(parent, wxID_ANY, "System Advisor Model (Open Source) Help", wxDefaultPosition, wxScaleSize(1000, 600)) - { - CreateAboutHtml(); - -#ifdef __WXMSW__ - SetIcon( wxICON( appicon ) ); -#endif - SetBackgroundColour( wxMetroTheme::Colour( wxMT_FOREGROUND ) ); - -#if defined(__WXMSW__)||defined(__WXOSX__) - m_webView = wxWebView::New( this, ID_BROWSER, ::wxWebViewDefaultURLStr, wxDefaultPosition, wxDefaultSize, - ::wxWebViewBackendDefault, wxBORDER_NONE ); - m_webView->SetPage( m_aboutHtml, "About SAM" ); -#else - m_htmlView = new wxHtmlWindow( this, ID_BROWSER ); - m_htmlView->SetPage( m_aboutHtml ); -#endif - - wxBoxSizer *tools = new wxBoxSizer( wxHORIZONTAL ); -//#if defined(__WXMSW__)||defined(__WXOSX__) -// tools->Add( new wxMetroButton( this, ID_BACK, "Back" ), 0, wxALL|wxEXPAND, 0 ); -//#endif - tools->Add( new wxMetroButton( this, ID_HOME, "Home" ), 0, wxALL|wxEXPAND, 0 ); -// tools->Add( new wxMetroButton( this, ID_WEBSITE, "Web site" ), 0, wxALL|wxEXPAND, 0 ); -// tools->Add( new wxMetroButton( this, ID_FORUM, "Forum" ), 0, wxALL|wxEXPAND, 0 ); -// tools->Add( new wxMetroButton( this, ID_EMAIL_SUPPORT, "Email support" ), 0, wxALL|wxEXPAND, 0 ); -// tools->Add( new wxMetroButton( this, ID_RELEASE_NOTES, "Release notes" ), 0, wxALL|wxEXPAND, 0 ); -// tools->Add( new wxMetroButton( this, ID_SCRIPT_REFERENCE, "Scripting reference" ), 0, wxALL|wxEXPAND, 0 ); - tools->AddStretchSpacer(); - tools->Add( new wxMetroButton( this, wxID_ABOUT, "About" ), 0, wxALL|wxEXPAND, 0 ); - tools->Add( new wxMetroButton( this, wxID_CLOSE, "Close" ), 0, wxALL|wxEXPAND, 0 ); - - wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); - sizer->Add( tools, 0, wxALL|wxEXPAND, 0 ); -#if defined(__WXMSW__)||defined(__WXOSX__) - sizer->Add( m_webView, 1, wxALL|wxEXPAND, 0 ); -#else - sizer->Add( m_htmlView, 1, wxALL|wxEXPAND, 0 ); -#endif - SetSizer( sizer ); - } - - void CreateAboutHtml() - { - - wxString proxy( wxEasyCurl::GetProxyForURL( SamApp::WebApi("website") )); - if ( proxy.IsEmpty() ) proxy = "default"; - else proxy = "proxy: " + proxy; - int patch = SamApp::RevisionNumber(); - wxString patchStr; - if ( patch > 0 ) - patchStr.Printf( ", updated to revision %d", patch ); - - // int nbit = (sizeof(void*) == 8) ? 64 : 32; - m_aboutHtml = "" - "System Advisor Model (Open Source)

" - "BSD 3-Clause License

Copyright (c) Alliance for Sustainable Energy, LLC. See also https://github.com/NREL/SAM/blob/develop/LICENSE
All rights reserved.
" - - "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met :

" - - "1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

" - - "2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and /or other materials provided with the distribution.

" - - "3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

" - - "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - "

"; - } - void LoadPage( wxString url ) - { - if ( url == ":about" ) - { -#if defined(__WXMSW__)||defined(__WXOSX__) - m_webView->SetPage( m_aboutHtml, "About SAM" ); -#else - m_htmlView->SetPage( m_aboutHtml ); -#endif - - return; - } - else if ( url == ":release_notes" ) - { - url = SamApp::WebApi("release_notes"); - } - else if ( url == ":email_support" ) - { - wxLaunchDefaultBrowser( SamApp::WebApi("support_email") ); - return; - } - else if ( url == ":script_ref" ) - { - wxFileName file( SamApp::GetRuntimePath() + "/help/lk_guide.pdf" ); - file.Normalize(); - wxLaunchDefaultBrowser( file.GetFullPath() ); - return; - } - else if ( url == ":forum" ) - url = SamApp::WebApi( "website" ) + "/forum.html"; - else if ( url == ":website" ) - url = SamApp::WebApi( "website" ); - -#if defined(__WXMSW__)||defined(__WXOSX__) - m_webView->LoadURL( url ); -#else - wxLaunchDefaultBrowser( url ); -#endif - } - - - void OnClose( wxCloseEvent &evt ) - { - Hide(); - evt.Veto(); - } - - void OnCommand( wxCommandEvent &evt ) - { - switch( evt.GetId() ) - { - case ID_BACK: -#if defined(__WXMSW__)||defined(__WXOSX__) - if ( m_webView->CanGoBack() ) m_webView->GoBack(); -#endif - break; - case ID_WEBSITE: - LoadPage( ":website" ); - break; - case ID_FORUM: - LoadPage( ":forum" ); - break; - case ID_EMAIL_SUPPORT: - LoadPage( ":email_support" ); - break; - case ID_RELEASE_NOTES: - LoadPage( ":release_notes" ); - break; - case ID_SCRIPT_REFERENCE: - LoadPage( ":script_ref" ); - break; - case ID_HOME: - { - wxFileName fn( SamApp::GetRuntimePath() + "/help/html/index.html" ); - fn.MakeAbsolute(); - LoadPage( "file:///" + fn.GetFullPath() ); - } - break; - case wxID_ABOUT: - LoadPage( ":about" ); - break; - case wxID_CLOSE: - Close(); - break; - } - } - -#if defined(__WXMSW__)||defined(__WXOSX__) - void OnNewWindow( wxWebViewEvent &evt ) - { - wxLaunchDefaultBrowser( evt.GetURL() ); - } -#endif - - DECLARE_EVENT_TABLE(); -}; - -BEGIN_EVENT_TABLE( HelpWin, wxFrame ) - EVT_BUTTON( ID_BACK, HelpWin::OnCommand ) - EVT_BUTTON( ID_HOME, HelpWin::OnCommand ) - EVT_BUTTON( ID_WEBSITE, HelpWin::OnCommand ) - EVT_BUTTON( ID_FORUM, HelpWin::OnCommand ) - EVT_BUTTON( ID_RELEASE_NOTES, HelpWin::OnCommand ) - EVT_BUTTON( ID_SCRIPT_REFERENCE, HelpWin::OnCommand ) - EVT_BUTTON( ID_EMAIL_SUPPORT, HelpWin::OnCommand ) - EVT_BUTTON( wxID_CLOSE, HelpWin::OnCommand ) - EVT_BUTTON( wxID_ABOUT, HelpWin::OnCommand ) -#if defined(__WXMSW__)||defined(__WXOSX__) - EVT_WEBVIEW_NEWWINDOW( ID_BROWSER, HelpWin::OnNewWindow ) -#endif - EVT_CLOSE( HelpWin::OnClose ) -END_EVENT_TABLE() - - -class HelpWin; -static HelpWin* gs_helpWin = 0; + wxString proxy(wxEasyCurl::GetProxyForURL(SamApp::WebApi("website"))); + if (proxy.IsEmpty()) proxy = "default"; + else proxy = "proxy: " + proxy; + + int patch = SamApp::RevisionNumber(); + wxString patchStr; + if (patch > 0) + patchStr.Printf(", updated to revision %d", patch); + + // int nbit = (sizeof(void*) == 8) ? 64 : 32; + return "" + "

System Advisor Model (SAM)

" + "

Open Source Build

" + "

BSD 3-Clause License

Copyright (c) Alliance for Sustainable Energy, LLC. See also https://github.com/NREL/SAM/blob/develop/LICENSE.

" + "

All rights reserved.

" + "

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

" + "
    " + "
  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. " + "
  3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  4. " + "
  5. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  6. " + "
" + "

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

" + ""; +}