efgshow.cc

来自「Gambit 是一个游戏库理论软件」· CC 代码 · 共 1,766 行 · 第 1/4 页

CC
1,766
字号
  for (int i = 1; i <= m_profiles.Length(); i++) {    m_profiles[i].Invalidate();  }  m_treeWindow->RefreshLabels();  m_treeWindow->Refresh();  m_outcomeWindow->UpdateValues();  m_profileTable->UpdateValues();}gText EfgShow::UniqueOutcomeName(void) const{  int number = m_efg.NumOutcomes() + 1;  while (1) {    int i;    for (i = 1; i <= m_efg.NumOutcomes(); i++) {      if (m_efg.GetOutcomeName(m_efg.GetOutcome(i)) == "Outcome" + ToText(number)) {	break;      }    }    if (i > m_efg.NumOutcomes()) {      return "Outcome" + ToText(number);    }        number++;  }}void EfgShow::OnSupportsEdited(void){  m_treeWindow->SupportChanged();  m_supportWindow->UpdateValues();}gText EfgShow::UniqueSupportName(void) const{  int number = m_supports.Length() + 1;  while (1) {    int i;    for (i = 1; i <= m_supports.Length(); i++) {      if (m_supports[i]->GetName() == "Support" + ToText(number)) {	break;      }    }    if (i > m_supports.Length())      return "Support" + ToText(number);        number++;  }}void EfgShow::SetFilename(const wxString &p_name){  m_filename = p_name;  if (m_filename != "") {    SetTitle(wxString::Format("Gambit - [%s] %s", m_filename.c_str(), 			      (char *) m_efg.GetTitle()));  }  else {    SetTitle(wxString::Format("Gambit - %s", (char *) m_efg.GetTitle()));  }  wxGetApp().SetFilename(this, p_name.c_str());}EFSupport *EfgShow::GetSupport(void){  return m_currentSupport;}void EfgShow::SetSupportNumber(int p_number){  if (p_number >= 1 && p_number <= m_supports.Length()) {    m_currentSupport = m_supports[p_number];    OnSupportsEdited();  }}int EfgShow::NumDecimals(void) const{  return m_treeWindow->DrawSettings().NumDecimals();}void EfgShow::OnTreeChanged(bool p_nodesChanged, bool p_infosetsChanged){  if (p_infosetsChanged) {    while (m_supports.Length()) {       delete m_supports.Remove(1);    }    m_currentSupport = new EFSupport(m_efg);    m_supports.Append(m_currentSupport);    m_currentSupport->SetName("Full Support");    OnSupportsEdited();  }  if (p_infosetsChanged || p_nodesChanged) {    // It would be nice to relax this, but be conservative for now    m_copyNode = 0;    if (m_cutNode) {      m_treeWindow->SetCutNode(m_cutNode, false);      m_cutNode = 0;    }    m_treeWindow->RefreshTree();    m_treeWindow->Refresh();  }    UpdateMenus();}void EfgShow::SetCursor(Node *p_node){  if (m_treeWindow) {    m_treeWindow->SetCursorPosition(p_node);  }  if (m_navigateWindow) {    m_navigateWindow->Set(p_node);  }  m_cursor = p_node;  UpdateMenus();}//--------------------------------------------------------------------//          EfgShow: Creating and updating menus and toolbar//--------------------------------------------------------------------void EfgShow::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");  editMenu->AppendSeparator();  editMenu->Append(efgmenuEDIT_INSERT, "&Insert", "Insert a move");  editMenu->Append(efgmenuEDIT_DELETE, "&Delete...", "Delete an object");  editMenu->Append(efgmenuEDIT_REVEAL, "&Reveal", 		   "Reveal choice at node");  editMenu->AppendSeparator();  editMenu->Append(efgmenuEDIT_TOGGLE_SUBGAME, "Mark &subgame",		   "Mark or unmark the subgame at this node");  editMenu->Append(efgmenuEDIT_MARK_SUBGAME_TREE, "Mar&k subgame tree",		   "Mark all subgames in this subtree");  editMenu->Append(efgmenuEDIT_UNMARK_SUBGAME_TREE, "&Unmark subgame tree",		   "Unmark all subgames in this subtree");  editMenu->AppendSeparator();  editMenu->Append(efgmenuEDIT_NODE, "&Node",		   "Edit properties of the node");  editMenu->Append(efgmenuEDIT_MOVE, "&Move",		   "Edit properties of the move");  editMenu->Append(efgmenuEDIT_GAME, "&Game",		   "Edit properties of the game");  wxMenu *toolsMenu = new wxMenu;  toolsMenu->Append(efgmenuTOOLS_DOMINANCE, "&Dominance",		    "Find undominated actions");  toolsMenu->Append(efgmenuTOOLS_EQUILIBRIUM, "&Equilibrium",		    "Compute Nash equilibria and refinements");  toolsMenu->Append(efgmenuTOOLS_QRE, "&Qre",		    "Compute quantal response equilibria");  wxMenu *toolsNfgMenu = new wxMenu;  toolsNfgMenu->Append(efgmenuTOOLS_NFG_REDUCED, "Reduced",		       "Generate reduced normal form");  toolsNfgMenu->Append(efgmenuTOOLS_NFG_AGENT, "Agent",		       "Generate agent normal form");  toolsMenu->Append(efgmenuTOOLS_NFG, "Normal form", toolsNfgMenu,		    "Create a normal form representation of this game");    wxMenu *viewMenu = new wxMenu;  viewMenu->Append(efgmenuVIEW_PROFILES, "&Profiles",		   "Display/hide profiles window", true);  viewMenu->Check(efgmenuVIEW_PROFILES, false);  viewMenu->AppendSeparator();  viewMenu->Append(efgmenuVIEW_NAVIGATION, "&Navigation",		   "Display navigation window", true);  viewMenu->Check(efgmenuVIEW_NAVIGATION, false);  viewMenu->Append(efgmenuVIEW_OUTCOMES, "&Outcomes",		   "Display and edit outcomes", true);  viewMenu->Check(efgmenuVIEW_OUTCOMES, false);  viewMenu->Append(efgmenuVIEW_SUPPORTS, "&Supports",		   "Display and edit supports", true);  viewMenu->Check(efgmenuVIEW_SUPPORTS, false);  viewMenu->AppendSeparator();  viewMenu->Append(efgmenuVIEW_ZOOMIN, "Zoom &in",		   "Increase display magnification");  viewMenu->Append(efgmenuVIEW_ZOOMOUT, "Zoom &out",		   "Decrease display magnification");  viewMenu->AppendSeparator();  viewMenu->Append(efgmenuVIEW_SUPPORT_REACHABLE, "&Root Reachable",		   "Display only nodes that are support-reachable",		   true);    wxMenu *formatMenu = new wxMenu;  wxMenu *formatDisplayMenu = new wxMenu;  formatDisplayMenu->Append(efgmenuFORMAT_DISPLAY_LAYOUT, "&Layout",			    "Set tree layout parameters");  formatDisplayMenu->Append(efgmenuFORMAT_DISPLAY_LEGEND, "Le&gends",			    "Set legends");  formatDisplayMenu->Append(efgmenuFORMAT_DISPLAY_COLORS, "&Colors",			    "Set colors");  formatDisplayMenu->Append(efgmenuFORMAT_DISPLAY_DECIMALS, "&Decimal Places",			   "Set number of decimal places to display");  formatMenu->Append(efgmenuFORMAT_DISPLAY, "&Display", formatDisplayMenu,		     "Set display options");    wxMenu *formatFontsMenu = new wxMenu;  formatFontsMenu->Append(efgmenuFORMAT_FONTS_ABOVENODE, "Above Node",			 "Font for label above nodes");  formatFontsMenu->Append(efgmenuFORMAT_FONTS_BELOWNODE, "Below Node",			 "Font for label below nodes");  formatFontsMenu->Append(efgmenuFORMAT_FONTS_AFTERNODE, "After Node",			 "Font for label to right of nodes");  formatFontsMenu->Append(efgmenuFORMAT_FONTS_ABOVEBRANCH, "Above Branch",			 "Font for label above branches");  formatFontsMenu->Append(efgmenuFORMAT_FONTS_BELOWBRANCH, "Below Branch",			 "Font for label below branches");  formatMenu->Append(efgmenuFORMAT_FONTS, "&Fonts", formatFontsMenu,		     "Set display fonts");    wxMenu *helpMenu = new wxMenu;  helpMenu->Append(wxID_ABOUT, "&About", "About Gambit");  wxMenuBar *menuBar = new wxMenuBar(wxMB_DOCKABLE);  menuBar->Append(fileMenu, "&File");  menuBar->Append(editMenu, "&Edit");  menuBar->Append(viewMenu, "&View");  menuBar->Append(formatMenu, "&Format");  menuBar->Append(toolsMenu, "&Tools");  menuBar->Append(helpMenu, "&Help");  // Set the menu bar  SetMenuBar(menuBar);}void EfgShow::UpdateMenus(void){  Node *cursor = Cursor();  wxMenuBar *menuBar = GetMenuBar();  menuBar->Enable(wxID_COPY, (cursor) ? true : false);  menuBar->Enable(wxID_CUT, (cursor) ? true : false);  menuBar->Enable(wxID_PASTE, (m_cutNode || m_copyNode) ? true : false);  menuBar->Enable(efgmenuEDIT_INSERT, (cursor) ? true : false);  menuBar->Enable(efgmenuEDIT_DELETE,		  (cursor && m_efg.NumChildren(cursor) > 0) ? true : false);  menuBar->Enable(efgmenuEDIT_REVEAL, 		  (cursor && cursor->GetInfoset()) ? true : false);  menuBar->Enable(efgmenuEDIT_TOGGLE_SUBGAME,		  (cursor && m_efg.IsLegalSubgame(cursor) &&		   cursor->GetParent()));  menuBar->Enable(efgmenuEDIT_MARK_SUBGAME_TREE,		  (cursor && m_efg.IsLegalSubgame(cursor)));  menuBar->Enable(efgmenuEDIT_UNMARK_SUBGAME_TREE,		  (cursor && m_efg.IsLegalSubgame(cursor)));  menuBar->SetLabel(efgmenuEDIT_TOGGLE_SUBGAME,		    (cursor && cursor->GetParent() &&		     m_efg.IsLegalSubgame(cursor) &&		     cursor->GetSubgameRoot() == cursor) ?		    "Unmark &subgame" : "Mark &subgame");  menuBar->Enable(efgmenuEDIT_NODE, (cursor) ? true : false);  menuBar->Enable(efgmenuEDIT_MOVE,		  (cursor && cursor->GetInfoset()) ? true : false);  if (m_treeWindow) {    menuBar->Check(efgmenuVIEW_SUPPORT_REACHABLE,		   m_treeWindow->DrawSettings().RootReachable());  }  m_treeWindow->UpdateMenus();}#include "bitmaps/new.xpm"#include "bitmaps/open.xpm"#include "bitmaps/save.xpm"#include "bitmaps/preview.xpm"#include "bitmaps/print.xpm"#include "bitmaps/zoomin.xpm"#include "bitmaps/zoomout.xpm"#include "bitmaps/help.xpm"void EfgShow::MakeToolbar(void){  wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_DOCKABLE |				     wxTB_HORIZONTAL);  toolBar->SetMargins(4, 4);  toolBar->AddTool(wxID_NEW, wxBITMAP(new), wxNullBitmap, false,		   -1, -1, 0, "New game", "Create a new game");  toolBar->AddTool(wxID_OPEN, wxBITMAP(open), wxNullBitmap, false,		   -1, -1, 0, "Open file", "Open a saved game");  toolBar->AddTool(wxID_SAVE, wxBITMAP(save), wxNullBitmap, false,		   -1, -1, 0, "Save game", "Save this game");  toolBar->AddSeparator();  toolBar->AddTool(wxID_PREVIEW, wxBITMAP(preview), wxNullBitmap,		   false, -1, -1, 0, "Print Preview",		   "View a preview of the game printout");  toolBar->AddTool(wxID_PRINT, wxBITMAP(print), wxNullBitmap, false,		   -1, -1, 0, "Print", "Print this game");  toolBar->AddSeparator();  toolBar->AddTool(efgmenuVIEW_ZOOMIN, wxBITMAP(zoomin), wxNullBitmap,		   false, -1, -1, 0, "Zoom in", "Increase magnification");  toolBar->AddTool(efgmenuVIEW_ZOOMOUT, wxBITMAP(zoomout), wxNullBitmap,		   false, -1, -1, 0, "Zoom out", "Decrease magnification");  toolBar->AddSeparator();  toolBar->AddTool(wxID_ABOUT, wxBITMAP(help), wxNullBitmap, false,		   -1, -1, 0, "Help", "Table of contents");  toolBar->Realize();  toolBar->SetRows(1);}//----------------------------------------------------------------------//               EfgShow: Menu handlers - File menu//----------------------------------------------------------------------void EfgShow::OnFileNew(wxCommandEvent &){  wxGetApp().OnFileNew(this);}void EfgShow::OnFileOpen(wxCommandEvent &){  wxGetApp().OnFileOpen(this);}void EfgShow::OnFileSave(wxCommandEvent &p_event){  if (p_event.GetId() == wxID_SAVEAS || m_filename == "") {    wxFileDialog dialog(this, "Choose file", wxPathOnly(m_filename),			wxFileNameFromPath(m_filename), "*.efg",			wxSAVE | wxOVERWRITE_PROMPT);    switch (dialog.ShowModal()) {    case wxID_OK:      SetFilename(dialog.GetPath());      break;    case wxID_CANCEL:    default:      return;    }  }  efgGame *efg = 0;  try {    gFileOutput file(m_filename);    efg = CompressEfg(m_efg, *GetSupport());    efg->WriteEfgFile(file, 6);    m_efg.SetIsDirty(false);    delete efg;  }  catch (gFileOutput::OpenFailed &) {    wxMessageBox(wxString::Format("Could not open %s for writing.",				  m_filename.c_str()),		 "Error", wxOK, this);    if (efg)  delete efg;  }  catch (gFileOutput::WriteFailed &) {    wxMessageBox(wxString::Format("Write error occurred in saving %s.\n",				  m_filename.c_str()),		 "Error", wxOK, this);    if (efg)  delete efg;  }  catch (efgGame::Exception &) {    wxMessageBox("Internal exception in extensive form", "Error",		 wxOK, this);    if (efg)  delete efg;  }}void EfgShow::OnFilePageSetup(wxCommandEvent &){  wxPageSetupDialog dialog(this, &m_pageSetupData);  if (dialog.ShowModal() == wxID_OK) {    m_printData = dialog.GetPageSetupData().GetPrintData();    m_pageSetupData = dialog.GetPageSetupData();  }}void EfgShow::OnFilePrintPreview(wxCommandEvent &){  wxPrintDialogData data(m_printData);  wxPrintPreview *preview =     new wxPrintPreview(new EfgPrintout(m_treeWindow,(char *) m_efg.GetTitle()),		       new EfgPrintout(m_treeWindow,(char *) m_efg.GetTitle()),		       &data);  if (!preview->Ok()) {    delete preview;    return;  }  wxPreviewFrame *frame = new wxPreviewFrame(preview, this,					     "Print Preview",					     wxPoint(100, 100),					     wxSize(600, 650));  frame->Initialize();  frame->Show(true);}void EfgShow::OnFilePrint(wxCommandEvent &){  wxPrintDialogData data(m_printData);  wxPrinter printer(&data);  EfgPrintout printout(m_treeWindow, (char *) m_efg.GetTitle());  if (!printer.Print(this, &printout, true)) {    if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {      wxMessageBox("There was an error in printing", "Error", wxOK);    }    // Otherwise, user hit "cancel"; just be quiet and return.    return;  }  else {    m_printData = printer.GetPrintDialogData().GetPrintData();  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?