📄 nfgshow.cc
字号:
//// $Source: /home/gambit/CVS/gambit/sources/gui/nfgshow.cc,v $// $Date: 2002/09/12 18:56:13 $// $Revision: 1.52.2.7 $//// DESCRIPTION:// Implementation of normal form display class//// This file is part of Gambit// Copyright (c) 2002, The Gambit Project//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//#include "wx/wxprec.h"#ifndef WX_PRECOMP#include "wx/wx.h"#endif // WX_PRECOMP#include "wx/notebook.h"#include "wx/grid.h"#include "wx/fontdlg.h"#include "dlspinctrl.h"#include "wxstatus.h"#include "nfgshow.h"#include "nfgtable.h"#include "nfgprint.h"#include "nfgprofile.h"#include "nfgnavigate.h"#include "nfgoutcome.h"#include "nfgsupport.h"#include "nfgconst.h"#include "game/efg.h"#include "game/efgutils.h"#include "nash/behavsol.h"#include "game/nfplayer.h"#include "game/nfgciter.h"#include "gambit.h"#include "efgshow.h"#include "dlnfgstrategies.h"#include "dleditcont.h"#include "dlnfgproperties.h"#include "dleditmixed.h"#include "dlelimmixed.h"#include "dlnfgnash.h"#include "dlnfgqre.h"#include "dlqrefile.h"#include "dlreport.h"#include "nash/nfgqre.h"#include "nash/nfgqregrid.h"//=====================================================================// Implementation of class NfgShow//=====================================================================const int idSOLUTIONWINDOW = 3002;const int idINFONOTEBOOK = 3003;const int idINFOWINDOW = 3004;BEGIN_EVENT_TABLE(NfgShow, wxFrame) EVT_MENU(wxID_NEW, NfgShow::OnFileNew) EVT_MENU(wxID_OPEN, NfgShow::OnFileOpen) EVT_MENU(wxID_CLOSE, NfgShow::Close) EVT_MENU(wxID_SAVE, NfgShow::OnFileSave) EVT_MENU(wxID_SAVEAS, NfgShow::OnFileSave) EVT_MENU(wxID_PRINT_SETUP, NfgShow::OnFilePageSetup) EVT_MENU(wxID_PREVIEW, NfgShow::OnFilePrintPreview) EVT_MENU(wxID_PRINT, NfgShow::OnFilePrint) EVT_MENU(wxID_EXIT, NfgShow::OnFileExit) EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, NfgShow::OnFileMRUFile) EVT_MENU(NFG_EDIT_STRATS, NfgShow::OnEditStrategies) EVT_MENU(NFG_EDIT_CONTINGENCY, NfgShow::OnEditContingency) EVT_MENU(NFG_EDIT_GAME, NfgShow::OnEditGame) EVT_MENU(NFG_VIEW_PROFILES, NfgShow::OnViewProfiles) EVT_MENU(NFG_VIEW_NAVIGATION, NfgShow::OnViewNavigation) EVT_MENU(NFG_VIEW_OUTCOMES, NfgShow::OnViewOutcomes) EVT_MENU(NFG_VIEW_SUPPORTS, NfgShow::OnViewSupports) EVT_MENU(NFG_VIEW_DOMINANCE, NfgShow::OnViewDominance) EVT_MENU(NFG_VIEW_PROBABILITIES, NfgShow::OnViewProbabilities) EVT_MENU(NFG_VIEW_VALUES, NfgShow::OnViewValues) EVT_MENU(NFG_VIEW_OUTCOME_LABELS, NfgShow::OnViewOutcomeLabels) EVT_MENU(NFG_FORMAT_DISPLAY_DECIMALS, NfgShow::OnFormatDisplayDecimals) EVT_MENU(NFG_FORMAT_FONT_DATA, NfgShow::OnFormatFontData) EVT_MENU(NFG_FORMAT_FONT_LABELS, NfgShow::OnFormatFontLabels) EVT_MENU(NFG_TOOLS_DOMINANCE, NfgShow::OnToolsDominance) EVT_MENU(NFG_TOOLS_EQUILIBRIUM, NfgShow::OnToolsEquilibrium) EVT_MENU(NFG_TOOLS_QRE, NfgShow::OnToolsQre) EVT_MENU(wxID_ABOUT, NfgShow::OnHelpAbout) EVT_MENU(NFG_SUPPORT_DUPLICATE, NfgShow::OnSupportDuplicate) EVT_MENU(NFG_SUPPORT_DELETE, NfgShow::OnSupportDelete) EVT_MENU(NFG_PROFILES_NEW, NfgShow::OnProfilesNew) EVT_MENU(NFG_PROFILES_DUPLICATE, NfgShow::OnProfilesDuplicate) EVT_MENU(NFG_PROFILES_DELETE, NfgShow::OnProfilesDelete) EVT_MENU(NFG_PROFILES_PROPERTIES, NfgShow::OnProfilesProperties) EVT_MENU(NFG_PROFILES_REPORT, NfgShow::OnProfilesReport) EVT_LIST_ITEM_ACTIVATED(idNFG_SOLUTION_LIST, NfgShow::OnProfilesProperties) EVT_LIST_ITEM_SELECTED(idNFG_SOLUTION_LIST, NfgShow::OnProfileSelected) EVT_SIZE(NfgShow::OnSize) EVT_CLOSE(NfgShow::OnCloseWindow) EVT_SASH_DRAGGED(idINFOWINDOW, NfgShow::OnSashDrag) EVT_SASH_DRAGGED(idSOLUTIONWINDOW, NfgShow::OnSashDrag) EVT_SET_FOCUS(NfgShow::OnSetFocus) EVT_NOTEBOOK_PAGE_CHANGED(idINFONOTEBOOK, NfgShow::OnInfoNotebookPage)END_EVENT_TABLE()//----------------------------------------------------------------------// NfgShow: Constructor and destructor//----------------------------------------------------------------------NfgShow::NfgShow(Nfg &p_nfg, wxWindow *p_parent) : wxFrame(p_parent, -1, "", wxDefaultPosition, wxSize(500, 500)), m_nfg(p_nfg), m_table(0), m_profileTable(0), m_solutionSashWindow(0), m_infoSashWindow(0), m_navigateWindow(0), m_outcomeWindow(0), m_supportWindow(0){#ifdef __WXMSW__ SetIcon(wxIcon("nfg_icn"));#else#include "bitmaps/nfg.xbm" SetIcon(wxIcon(nfg_bits, nfg_width, nfg_height));#endif // __WXMSW__ m_currentProfile = 0; m_currentSupport = new NFSupport(m_nfg); // base support m_currentSupport->SetName("Full Support"); m_supports.Append(m_currentSupport); MakeMenus(); wxAcceleratorEntry entries[5]; entries[0].Set(wxACCEL_CTRL, (int) 'N', wxID_NEW); entries[1].Set(wxACCEL_CTRL, (int) 'O', wxID_OPEN); entries[2].Set(wxACCEL_CTRL, (int) 'S', wxID_SAVE); entries[3].Set(wxACCEL_CTRL, (int) 'P', wxID_PRINT); entries[4].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT); wxAcceleratorTable accel(5, entries); SetAcceleratorTable(accel); CreateStatusBar(); MakeToolbar(); m_solutionSashWindow = new wxSashWindow(this, idSOLUTIONWINDOW, wxDefaultPosition, wxSize(600, 100)); m_solutionSashWindow->SetSashVisible(wxSASH_TOP, true); m_profileTable = new NfgProfileList(this, m_solutionSashWindow); m_profileTable->Show(false); m_solutionSashWindow->Show(false); m_infoSashWindow = new wxSashWindow(this, idINFOWINDOW, wxPoint(0, 40), wxSize(200, 200), wxNO_BORDER | wxSW_3D); m_infoSashWindow->SetSashVisible(wxSASH_RIGHT, true); m_infoSashWindow->Show(true); m_infoNotebook = new wxNotebook(m_infoSashWindow, idINFONOTEBOOK); m_infoNotebook->Show(true); m_navigateWindow = new NfgNavigateWindow(this, m_infoNotebook); m_navigateWindow->SetSize(200, 200); m_infoNotebook->AddPage(m_navigateWindow, "Navigation"); m_outcomeWindow = new NfgOutcomeWindow(this, m_infoNotebook); m_outcomeWindow->UpdateValues(); m_outcomeWindow->SetSize(200, 200); m_infoNotebook->AddPage(m_outcomeWindow, "Outcomes"); m_supportWindow = new NfgSupportWindow(this, m_infoNotebook); m_supportWindow->SetSize(200, 200); m_infoNotebook->AddPage(m_supportWindow, "Supports"); m_infoNotebook->SetSelection(0); m_table = new NfgTable(m_nfg, this); m_table->SetSize(0, 0, 200, 200); m_nfg.SetIsDirty(false); GetMenuBar()->Check(NFG_VIEW_OUTCOMES, !m_table->GetSettings().OutcomeValues()); UpdateMenus(); m_table->SetFocus(); AdjustSizes(); Show(true);}NfgShow::~NfgShow(){ wxGetApp().RemoveGame(&m_nfg);}//----------------------------------------------------------------------// NfgShow: Manipulation of profile list//----------------------------------------------------------------------void NfgShow::AddProfile(const MixedSolution &p_profile, bool p_map){ if (p_profile.GetName() == "") { MixedSolution tmp(p_profile); tmp.SetName(UniqueProfileName()); m_profiles.Append(tmp); } else { m_profiles.Append(p_profile); } if (m_nfg.AssociatedEfg() && p_map) { wxGetApp().GetWindow(m_nfg.AssociatedEfg())->AddProfile(BehavProfile<gNumber>(*p_profile.Profile()), false); } m_profileTable->UpdateValues(); UpdateMenus();}void NfgShow::RemoveProfile(int p_profile){ m_profiles.Remove(p_profile); if (m_currentProfile == p_profile) { m_currentProfile = (m_profiles.Length() > 0) ? 1 : 0; } else if (m_currentProfile > p_profile) { m_currentProfile--; } if (m_currentProfile > 0) { m_table->SetProfile(m_profiles[m_currentProfile]); } else { m_table->ClearProfile(); if (m_table->ShowProbs()) { m_table->ToggleProbs(); } if (m_table->ShowValues()) { m_table->ToggleValues(); } } m_profileTable->UpdateValues(); UpdateMenus();}void NfgShow::ChangeProfile(int sol){ m_currentProfile = sol; if (sol > 0) { m_table->SetProfile(m_profiles[m_currentProfile]); } else if (sol == 0) { if (m_table->ShowProbs()) { m_table->ToggleProbs(); GetMenuBar()->Check(NFG_VIEW_PROBABILITIES, false); } if (m_table->ShowValues()) { m_table->ToggleValues(); GetMenuBar()->Check(NFG_VIEW_VALUES, false); } } if (m_profileTable) { m_profileTable->UpdateValues(); }}void NfgShow::OnProfileSelected(wxListEvent &p_event){ m_currentProfile = p_event.GetIndex() + 1; m_table->SetProfile(m_profiles[m_currentProfile]);} gText NfgShow::UniqueProfileName(void) const{ int number = m_profiles.Length() + 1; while (1) { int i; for (i = 1; i <= m_profiles.Length(); i++) { if (m_profiles[i].GetName() == "Profile" + ToText(number)) { break; } } if (i > m_profiles.Length()) { return "Profile" + ToText(number); } number++; }}//----------------------------------------------------------------------// NfgShow: Coordinating updates of child windows//----------------------------------------------------------------------void NfgShow::SetPlayers(int p_rowPlayer, int p_colPlayer){ if (m_navigateWindow) { m_navigateWindow->SetPlayers(p_rowPlayer, p_colPlayer); } m_table->SetPlayers(p_rowPlayer, p_colPlayer);}void NfgShow::SetStrategy(int p_player, int p_strategy){ if (m_navigateWindow) { m_navigateWindow->SetStrategy(p_player, p_strategy); } if (m_table) { m_table->SetStrategy(p_player, p_strategy); }}void NfgShow::SetProfile(const gArray<int> &p_profile){ m_navigateWindow->SetProfile(p_profile); m_table->SetContingency(p_profile);}gArray<int> NfgShow::GetContingency(void) const{ return m_navigateWindow->GetProfile();}void NfgShow::UpdateProfile(gArray<int> &profile){ // m_table->OnChangeValues();}void NfgShow::OnOutcomesEdited(void){ for (int i = 1; i <= m_profiles.Length(); i++) { m_profiles[i].Invalidate(); } m_table->RefreshTable(); m_profileTable->UpdateValues();}gText NfgShow::UniqueOutcomeName(void) const{ int number = m_nfg.NumOutcomes() + 1; while (1) { int i; for (i = 1; i <= m_nfg.NumOutcomes(); i++) { if (m_nfg.Outcomes()[i]->GetName() == "Outcome" + ToText(number)) { break; } } if (i > m_nfg.NumOutcomes()) { return "Outcome" + ToText(number); } number++; }}//----------------------------------------------------------------------// NfgShow: Creating and updating menus and toolbar//----------------------------------------------------------------------void NfgShow::MakeMenus(void){ wxMenu *fileMenu = new wxMenu; fileMenu->Append(wxID_NEW, "&New\tCtrl-N", "Create a new game"); fileMenu->Append(wxID_OPEN, "&Open\tCtrl-O", "Open a saved game"); fileMenu->Append(wxID_CLOSE, "&Close", "Close this window"); fileMenu->AppendSeparator(); fileMenu->Append(wxID_SAVE, "&Save\tCtrl-S", "Save this game"); fileMenu->Append(wxID_SAVEAS, "Save &as", "Save game to a different file"); fileMenu->AppendSeparator(); fileMenu->Append(wxID_PRINT_SETUP, "Page Se&tup", "Set up preferences for printing"); fileMenu->Append(wxID_PREVIEW, "Print Pre&view", "View a preview of the game printout"); fileMenu->Append(wxID_PRINT, "&Print\tCtrl-P", "Print this game"); fileMenu->AppendSeparator(); fileMenu->Append(wxID_EXIT, "E&xit\tCtrl-X", "Exit Gambit"); wxMenu *editMenu = new wxMenu; editMenu->Append(wxID_CUT, "Cu&t", "Cut the current selection"); editMenu->Append(wxID_COPY, "&Copy", "Copy the current selection"); editMenu->Append(wxID_PASTE, "&Paste", "Paste from clipboard"); // For the moment, these are not implemented -- leave disabled editMenu->Enable(wxID_CUT, false); editMenu->Enable(wxID_COPY, false); editMenu->Enable(wxID_PASTE, false); editMenu->AppendSeparator(); editMenu->Append(NFG_EDIT_STRATS, "&Strategies", "Edit strategy names"); editMenu->Append(NFG_EDIT_CONTINGENCY, "&Contingency", "Edit the selected contingency"); editMenu->Append(NFG_EDIT_GAME, "&Game", "Edit game properties"); wxMenu *viewMenu = new wxMenu; viewMenu->Append(NFG_VIEW_PROFILES, "&Profiles", "Display/hide profiles window", true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -