3030#include < wx/txtstrm.h>
3131#include < wx/tokenzr.h>
3232#include < wx/process.h>
33- #include < wx/print.h>
3433
3534#include " wx/sheet/sheet.h"
36- #include " wx/plotctrl/plotctrl.h"
37- #include " wx/wxthings/spinctld.h" // for wxSpinCtrlDbl
3835
3936#include " gamedoc.h"
4037#include " menuconst.h" // for tool IDs
@@ -246,80 +243,6 @@ LogitBranchDialog::LogitBranchDialog(wxWindow *p_parent, GameDocument *p_doc,
246243 CenterOnParent ();
247244}
248245
249- // ========================================================================
250- // class gbtLogitPlotCtrl
251- // ========================================================================
252-
253- class gbtLogitPlotCtrl : public wxPlotCtrl {
254- double m_scaleFactor{1.0 };
255-
256- // / Overriding x (lambda) axis labeling
257- void CalcXAxisTickPositions () override ;
258-
259- public:
260- gbtLogitPlotCtrl (wxWindow *p_parent, GameDocument *p_doc);
261-
262- double LambdaToX (double p_lambda) const
263- {
264- return m_scaleFactor * p_lambda / (1.0 + m_scaleFactor * p_lambda);
265- }
266- double XToLambda (double p_x) const { return p_x / (m_scaleFactor * (1.0 - p_x)); }
267-
268- void SetScaleFactor (double p_scale) { m_scaleFactor = p_scale; }
269- };
270-
271- gbtLogitPlotCtrl::gbtLogitPlotCtrl (wxWindow *p_parent, GameDocument *p_doc) : wxPlotCtrl(p_parent)
272- {
273- SetAxisLabelColour (*wxBLUE);
274- const wxFont labelFont (8 , wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
275- SetAxisLabelFont (labelFont);
276- SetAxisColour (*wxBLUE);
277- SetAxisFont (labelFont);
278- SetDrawSymbols (false );
279-
280- // SetAxisFont resets the width of the y-axis labels, assuming
281- // a fairly long label.
282- int x = 6 , y = 12 , descent = 0 , leading = 0 ;
283- GetTextExtent (wxT (" 0.88" ), &x, &y, &descent, &leading, &labelFont);
284- m_y_axis_text_width = x + leading;
285-
286- SetXAxisLabel (wxT (" Lambda" ));
287- SetShowXAxisLabel (true );
288- SetYAxisLabel (wxT (" Probability" ));
289- SetShowYAxisLabel (true );
290-
291- SetShowKey (true );
292-
293- m_xAxisTick_step = 0.2 ;
294- SetViewRect (wxRect2DDouble (0 , 0 , 1 , 1 ));
295- }
296-
297- //
298- // This differs from the wxPlotWindow original only by the use of
299- // XToLambda() to construct the tick labels.
300- //
301- void gbtLogitPlotCtrl::CalcXAxisTickPositions ()
302- {
303- double current = ceil (m_viewRect.GetLeft () / m_xAxisTick_step) * m_xAxisTick_step;
304- m_xAxisTicks.Clear ();
305- m_xAxisTickLabels.Clear ();
306- const int windowWidth = GetPlotAreaRect ().width ;
307- for (int i = 0 ; i < m_xAxisTick_count; i++) {
308- if (!IsFinite (current, wxT (" axis label is not finite" ))) {
309- return ;
310- }
311-
312- int const x = GetClientCoordFromPlotX (current);
313-
314- if ((x >= -1 ) && (x < windowWidth + 2 )) {
315- m_xAxisTicks.Add (x);
316- m_xAxisTickLabels.Add (wxString::Format (m_xAxisTickFormat.c_str (), XToLambda (current)));
317- }
318-
319- current += m_xAxisTick_step;
320- }
321- }
322-
323246// ========================================================================
324247// class LogitPlotStrategyList
325248// ========================================================================
@@ -427,125 +350,6 @@ void LogitPlotStrategyList::OnLeftUp(wxSheetEvent &p_event)
427350 p_event.Skip ();
428351}
429352
430- // ========================================================================
431- // class LogitPlotPanel
432- // ========================================================================
433-
434- class LogitPlotPanel final : public wxPanel {
435- GameDocument *m_doc;
436- LogitMixedBranch m_branch;
437- LogitPlotStrategyList *m_plotStrategies;
438- gbtLogitPlotCtrl *m_plotCtrl;
439-
440- // Event handlers
441- void OnChangeStrategies (wxSheetEvent &) { Plot (); }
442-
443- public:
444- LogitPlotPanel (wxWindow *p_parent, GameDocument *p_doc);
445-
446- void AddProfile (const wxString &p_text) { m_branch.AddProfile (p_text); }
447-
448- void SetScaleFactor (double p_scale);
449- void FitZoom ();
450- void Plot ();
451-
452- LogitMixedBranch &GetBranch () { return m_branch; }
453- wxPlotCtrl *GetPlotCtrl () const { return m_plotCtrl; }
454- };
455-
456- LogitPlotPanel::LogitPlotPanel (wxWindow *p_parent, GameDocument *p_doc)
457- : wxPanel(p_parent, wxID_ANY), m_doc(p_doc), m_branch(p_doc),
458- m_plotStrategies(new LogitPlotStrategyList(this , p_doc)),
459- m_plotCtrl(new gbtLogitPlotCtrl(this , p_doc))
460- {
461- m_plotCtrl->SetSizeHints (wxSize (600 , 400 ));
462-
463- auto *playerSizer = new wxStaticBoxSizer (wxHORIZONTAL, this , wxT (" Show strategies" ));
464- playerSizer->Add (m_plotStrategies, 1 , wxALL | wxEXPAND, 5 );
465-
466- auto *sizer = new wxBoxSizer (wxHORIZONTAL);
467- sizer->Add (playerSizer, 0 , wxALL | wxEXPAND, 5 );
468- sizer->Add (m_plotCtrl, 0 , wxALL, 5 );
469-
470- Connect (m_plotStrategies->GetId (), wxEVT_SHEET_CELL_LEFT_UP,
471- (wxObjectEventFunction) reinterpret_cast <wxEventFunction>(wxStaticCastEvent (
472- wxSheetEventFunction,
473- static_cast <wxSheetEventFunction>(&LogitPlotPanel::OnChangeStrategies))));
474-
475- SetSizer (sizer);
476- wxWindowBase::Layout ();
477- }
478-
479- void LogitPlotPanel::Plot ()
480- {
481- if (m_branch.NumPoints () == 0 ) {
482- return ;
483- }
484-
485- m_plotCtrl->DeleteCurve (-1 );
486-
487- for (int st = 1 ; st <= m_doc->GetGame ()->GetStrategies ().size (); st++) {
488- if (!m_plotStrategies->IsStrategyShown (st)) {
489- continue ;
490- }
491-
492- auto *curve = new wxPlotData (m_branch.NumPoints ());
493-
494- const GameStrategy strategy = m_doc->GetGame ()->GetStrategy (st);
495- const GamePlayer player = strategy->GetPlayer ();
496-
497- curve->SetFilename (wxString (player->GetLabel ().c_str (), *wxConvCurrent) + wxT (" :" ) +
498- wxString (strategy->GetLabel ().c_str (), *wxConvCurrent));
499-
500- for (int i = 0 ; i < m_branch.NumPoints (); i++) {
501- curve->SetValue (i, m_plotCtrl->LambdaToX (m_branch.GetLambda (i + 1 )),
502- m_branch.GetProfile (i + 1 )[st]);
503- }
504-
505- curve->SetPen (wxPLOTPEN_NORMAL,
506- wxPen (m_doc->GetStyle ().GetPlayerColor (player), 1 , wxPENSTYLE_SOLID));
507-
508- m_plotCtrl->AddCurve (curve, false );
509- }
510- }
511-
512- void LogitPlotPanel::SetScaleFactor (double p_scale)
513- {
514- m_plotCtrl->SetScaleFactor (p_scale);
515- Plot ();
516- }
517-
518- void LogitPlotPanel::FitZoom () { m_plotCtrl->MakeCurveVisible (-1 ); }
519-
520- // ========================================================================
521- // class LogitPrintout
522- // ========================================================================
523-
524- class LogitPrintout : public wxPrintout {
525- wxPlotCtrl *m_plot;
526-
527- public:
528- LogitPrintout (wxPlotCtrl *p_plot, const wxString &p_label) : wxPrintout(p_label), m_plot(p_plot)
529- {
530- }
531- ~LogitPrintout () override = default ;
532-
533- bool OnPrintPage (int ) override
534- {
535- const wxSize size = GetDC ()->GetSize ();
536- m_plot->DrawWholePlot (GetDC (), wxRect (50 , 50 , size.GetWidth () - 100 , size.GetHeight () - 100 ));
537- return true ;
538- }
539- bool HasPage (int page) override { return (page <= 1 ); }
540- void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) override
541- {
542- *minPage = 1 ;
543- *maxPage = 1 ;
544- *selPageFrom = 1 ;
545- *selPageTo = 1 ;
546- }
547- };
548-
549353// ========================================================================
550354// class LogitMixedDialog
551355// ========================================================================
@@ -554,8 +358,6 @@ class LogitMixedDialog final : public wxDialog {
554358 GameDocument *m_doc;
555359 int m_pid{0 };
556360 wxProcess *m_process{nullptr };
557- LogitPlotPanel *m_plot;
558- wxSpinCtrlDbl *m_scaler;
559361 wxToolBar *m_toolBar;
560362 wxStaticText *m_statusText;
561363 wxButton *m_stopButton, *m_okButton;
@@ -567,11 +369,6 @@ class LogitMixedDialog final : public wxDialog {
567369 void OnIdle (wxIdleEvent &);
568370 void OnEndProcess (wxProcessEvent &);
569371 void OnSave (wxCommandEvent &);
570- void OnPrint (wxCommandEvent &);
571-
572- void OnChangeScale (wxSpinEvent &);
573- void OnZoomFit (wxCommandEvent &);
574- void OnViewData (wxCommandEvent &);
575372
576373 void Start ();
577374
@@ -590,9 +387,6 @@ EVT_END_PROCESS(GBT_ID_PROCESS, LogitMixedDialog::OnEndProcess)
590387EVT_IDLE(LogitMixedDialog::OnIdle)
591388EVT_TIMER(GBT_ID_TIMER, LogitMixedDialog::OnTimer)
592389EVT_MENU(wxID_SAVE, LogitMixedDialog::OnSave)
593- EVT_MENU(wxID_PRINT, LogitMixedDialog::OnPrint)
594- EVT_MENU(GBT_MENU_VIEW_ZOOMFIT, LogitMixedDialog::OnZoomFit)
595- EVT_MENU(GBT_MENU_VIEW_DATA, LogitMixedDialog::OnViewData)
596390END_EVENT_TABLE()
597391
598392#include " bitmaps/stop.xpm"
@@ -603,7 +397,7 @@ END_EVENT_TABLE()
603397
604398LogitMixedDialog::LogitMixedDialog (wxWindow *p_parent, GameDocument *p_doc)
605399 : wxDialog(p_parent, wxID_ANY, wxT(" Compute quantal response equilibria" ), wxDefaultPosition),
606- m_doc(p_doc), m_plot( new LogitPlotPanel( this , m_doc)), m_timer(this , GBT_ID_TIMER)
400+ m_doc(p_doc), m_timer(this , GBT_ID_TIMER)
607401{
608402 auto *sizer = new wxBoxSizer (wxVERTICAL);
609403
@@ -648,20 +442,10 @@ LogitMixedDialog::LogitMixedDialog(wxWindow *p_parent, GameDocument *p_doc)
648442 wxITEM_NORMAL, _ (" Show the whole graph" ), _ (" Show the whole graph" ));
649443
650444 m_toolBar->AddControl (new wxStaticText (m_toolBar, wxID_STATIC, wxT (" Graph scaling:" )));
651- m_scaler = new wxSpinCtrlDbl (*m_toolBar, wxID_ANY, wxT (" " ), wxDefaultPosition, wxDefaultSize, 0 ,
652- 0.1 , 10.0 , 1.0 , 0.1 );
653- m_toolBar->AddControl (m_scaler);
654- Connect (m_scaler->GetId (), wxEVT_COMMAND_SPINCTRL_UPDATED,
655- wxSpinEventHandler (LogitMixedDialog::OnChangeScale));
656445
657446 m_toolBar->Realize ();
658447 sizer->Add (m_toolBar, 0 , wxALL | wxEXPAND, 5 );
659448
660- auto *midSizer = new wxBoxSizer (wxHORIZONTAL);
661- midSizer->Add (m_plot, 0 , wxALL | wxALIGN_CENTER, 5 );
662-
663- sizer->Add (midSizer, 0 , wxALL | wxALIGN_CENTER, 5 );
664-
665449 auto *buttonSizer = new wxBoxSizer (wxHORIZONTAL);
666450 m_okButton = new wxButton (this , wxID_OK, wxT (" OK" ));
667451 buttonSizer->Add (m_okButton, 0 , wxALL | wxALIGN_CENTER, 5 );
@@ -729,7 +513,6 @@ void LogitMixedDialog::OnIdle(wxIdleEvent &p_event)
729513
730514 wxString msg;
731515 msg << tis.ReadLine ();
732- m_plot->AddProfile (msg);
733516 // m_mixedList->AddProfile(msg, false);
734517 m_output += msg;
735518 m_output += wxT (" \n " );
@@ -755,7 +538,6 @@ void LogitMixedDialog::OnEndProcess(wxProcessEvent &p_event)
755538 msg << tis.ReadLine ();
756539
757540 if (msg != wxT (" " )) {
758- m_plot->AddProfile (msg);
759541 // m_mixedList->AddProfile(msg, true);
760542 m_output += msg;
761543 m_output += wxT (" \n " );
@@ -774,7 +556,6 @@ void LogitMixedDialog::OnEndProcess(wxProcessEvent &p_event)
774556 m_okButton->Enable (true );
775557 m_toolBar->EnableTool (wxID_SAVE, true );
776558 m_toolBar->EnableTool (GBT_MENU_VIEW_DATA, true );
777- m_plot->Plot ();
778559}
779560
780561void LogitMixedDialog::OnStop (wxCommandEvent &)
@@ -803,35 +584,6 @@ void LogitMixedDialog::OnSave(wxCommandEvent &)
803584 }
804585}
805586
806- void LogitMixedDialog::OnPrint (wxCommandEvent &)
807- {
808- wxPrintDialogData data;
809- wxPrinter printer (&data);
810-
811- wxPrintout *printout = new LogitPrintout (m_plot->GetPlotCtrl (), wxT (" Logit correspondence" ));
812-
813- if (!printer.Print (this , printout, true )) {
814- if (wxPrinter::GetLastError () == wxPRINTER_ERROR) {
815- wxMessageBox (_ (" There was an error in printing" ), _ (" Error" ), wxOK);
816- }
817- // Otherwise, user hit "cancel"; just be quiet and return.
818- return ;
819- }
820- }
821-
822- void LogitMixedDialog::OnChangeScale (wxSpinEvent &)
823- {
824- m_plot->SetScaleFactor (m_scaler->GetValue ());
825- }
826-
827- void LogitMixedDialog::OnZoomFit (wxCommandEvent &) { m_plot->FitZoom (); }
828-
829- void LogitMixedDialog::OnViewData (wxCommandEvent &)
830- {
831- LogitBranchDialog dialog (this , m_doc, m_plot->GetBranch ());
832- dialog.ShowModal ();
833- }
834-
835587} // namespace
836588
837589// ========================================================================
0 commit comments