diff --git a/CMakeLists.txt b/CMakeLists.txt index cb98fe4..eee6a42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) project(ochess VERSION "0.0.0") # wxWidgets -find_package(wxWidgets COMPONENTS net gl core base adv aui REQUIRED) +find_package(wxWidgets COMPONENTS net gl core base adv aui propgrid REQUIRED) include(${wxWidgets_USE_FILE}) # Ochess diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 407ec80..b3ed9c4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1,5 +1,6 @@ #include "MainWindow.hpp" #include "ChessArbiter.hpp" +#include "engine_tab/EngineTab.hpp" #include "pgnp.hpp" #include "preferences/preferences.hpp" @@ -40,11 +41,16 @@ MainWindow::MainWindow() wxMenu *menuBase = new wxMenu; menuBase->Append(5, "New", "Create new database"); + // Engine menu + wxMenu *engineMenu = new wxMenu; + engineMenu->Append(6, "New", "Create a new engine configuration"); + /// Menu bar menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); menuBar->Append(menuGame, "&Game"); menuBar->Append(menuBase, "&Database"); + menuBar->Append(engineMenu, "&Engines"); SetMenuBar(menuBar); // Create the wxNotebook widget @@ -57,8 +63,12 @@ MainWindow::MainWindow() Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY); Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); - /*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/hartwig_tests.pgn"); - notebook->AddPage(bt, bt->GetLabel()); + /*BaseTab *bt = new BaseTab((wxFrame *)notebook, + "/home/loic/hartwig_tests.pgn"); notebook->AddPage(bt, bt->GetLabel()); + notebook->SetSelection(notebook->GetPageIndex(bt));*/ + + /*EngineTab *bt = new EngineTab((wxWindow *)notebook, + "/home/loic/.local/bin/stockfish"); notebook->AddPage(bt, bt->GetLabel()); notebook->SetSelection(notebook->GetPageIndex(bt));*/ } diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp new file mode 100644 index 0000000..12b065f --- /dev/null +++ b/src/engine_tab/EngineTab.cpp @@ -0,0 +1,21 @@ +#include "EngineTab.hpp" + +EngineTab::EngineTab(wxWindow *parent, std::string engine_path_or_name) + : EngineTabBF(parent), TabInfos(TabInfos::ENGINE) { + SetLabel("New Engine"); + engine = new uciadapter::UCI(engine_path_or_name); + engine_location->SetValue(engine_path_or_name); + std::vector opts = engine->GetOptions(); + for (uciadapter::Option &opt : opts) { + if (opt.type == "check") { + engine_parameters->Append(new wxBoolProperty( + opt.name, wxPG_LABEL, opt.default_value == "true")); + } else if (opt.type == "spin") { + engine_parameters->Append(new wxIntProperty( + opt.name, wxPG_LABEL, std::stoi(opt.default_value))); + } else if (opt.type == "string") { + engine_parameters->Append( + new wxStringProperty(opt.name, wxPG_LABEL, opt.default_value)); + } + } +} diff --git a/src/engine_tab/EngineTab.hpp b/src/engine_tab/EngineTab.hpp new file mode 100644 index 0000000..4538d0b --- /dev/null +++ b/src/engine_tab/EngineTab.hpp @@ -0,0 +1,13 @@ +#include "EngineTabBF.h" +#include "ochess.hpp" +#include "UCI.hpp" + +class EngineTab : public EngineTabBF, public TabInfos { + uciadapter::UCI *engine; + +public: + EngineTab(wxWindow *parent, std::string engine_path_or_name); + void ApplyPreferences() {} + void *GetGame() { return (NULL); } + void *GetBase() { return (NULL); }; +}; \ No newline at end of file diff --git a/src/engine_tab/EngineTabBF.cpp b/src/engine_tab/EngineTabBF.cpp new file mode 100644 index 0000000..e8cb184 --- /dev/null +++ b/src/engine_tab/EngineTabBF.cpp @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-40-g8042f487) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "EngineTabBF.h" + +/////////////////////////////////////////////////////////////////////////// + +EngineTabBF::EngineTabBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) +{ + wxBoxSizer* main_sizer; + main_sizer = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* engine_name_sizer; + engine_name_sizer = new wxBoxSizer( wxHORIZONTAL ); + + engine_name_label = new wxStaticText( this, wxID_ANY, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 ); + engine_name_label->Wrap( -1 ); + engine_name_sizer->Add( engine_name_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + engine_name = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + engine_name_sizer->Add( engine_name, 1, wxALL, 5 ); + + + main_sizer->Add( engine_name_sizer, 0, wxEXPAND, 5 ); + + wxBoxSizer* engine_location_sizer; + engine_location_sizer = new wxBoxSizer( wxHORIZONTAL ); + + engine_location_label = new wxStaticText( this, wxID_ANY, wxT("Location:"), wxDefaultPosition, wxDefaultSize, 0 ); + engine_location_label->Wrap( -1 ); + engine_location_sizer->Add( engine_location_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + engine_location = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); + engine_location_sizer->Add( engine_location, 1, wxALL, 5 ); + + + main_sizer->Add( engine_location_sizer, 0, wxEXPAND, 5 ); + + separator_1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + main_sizer->Add( separator_1, 0, wxEXPAND | wxALL, 5 ); + + params_label = new wxStaticText( this, wxID_ANY, wxT("Parameters:"), wxDefaultPosition, wxDefaultSize, 0 ); + params_label->Wrap( -1 ); + main_sizer->Add( params_label, 0, wxALL, 5 ); + + engine_parameters = new wxPropertyGrid(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_DEFAULT_STYLE|wxPG_SPLITTER_AUTO_CENTER); + main_sizer->Add( engine_parameters, 1, wxALL|wxEXPAND, 5 ); + + save_button = new wxButton( this, wxID_ANY, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 ); + main_sizer->Add( save_button, 0, wxALL|wxEXPAND, 5 ); + + + this->SetSizer( main_sizer ); + this->Layout(); +} + +EngineTabBF::~EngineTabBF() +{ +} diff --git a/src/engine_tab/EngineTabBF.h b/src/engine_tab/EngineTabBF.h new file mode 100644 index 0000000..8ce994a --- /dev/null +++ b/src/engine_tab/EngineTabBF.h @@ -0,0 +1,56 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-40-g8042f487) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class EngineTabBF +/////////////////////////////////////////////////////////////////////////////// +class EngineTabBF : public wxPanel +{ + private: + + protected: + wxStaticText* engine_name_label; + wxTextCtrl* engine_name; + wxStaticText* engine_location_label; + wxTextCtrl* engine_location; + wxStaticLine* separator_1; + wxStaticText* params_label; + wxPropertyGrid* engine_parameters; + wxButton* save_button; + + public: + + EngineTabBF( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + + ~EngineTabBF(); + +}; + diff --git a/src/ochess.hpp b/src/ochess.hpp index 2a71c13..89b983c 100644 --- a/src/ochess.hpp +++ b/src/ochess.hpp @@ -50,7 +50,7 @@ void Abort(std::string msg); */ class TabInfos { public: - typedef enum Type { GAME, BASE, NONE } Type; + typedef enum Type { GAME, BASE, ENGINE, NONE } Type; Type type; TabInfos(Type type_) : type(type_) {} virtual void ApplyPreferences() = 0; diff --git a/tools/wxframebuilder/EditorPanel.fbp b/tools/wxframebuilder/EditorPanel.fbp index 3ab937b..411938e 100644 --- a/tools/wxframebuilder/EditorPanel.fbp +++ b/tools/wxframebuilder/EditorPanel.fbp @@ -118,7 +118,7 @@ Editor 0 - + 1 1 1 @@ -169,16 +169,16 @@ wxTAB_TRAVERSAL - + editor_page_sizer wxVERTICAL protected - + 5 wxEXPAND 1 - + editor_canvas_sizer wxVERTICAL @@ -431,11 +431,11 @@ tags_page_sizer wxVERTICAL none - + 5 wxEXPAND 0 - + tags_list_control_sizer wxVERTICAL diff --git a/tools/wxframebuilder/EngineTab.fbp b/tools/wxframebuilder/EngineTab.fbp new file mode 100644 index 0000000..8bdd5ea --- /dev/null +++ b/tools/wxframebuilder/EngineTab.fbp @@ -0,0 +1,588 @@ + + + + + ; + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + EngineTabBF + 1000 + none + + + 0 + EngineTabBF + + ../../src/engine_tab/ + + 1 + 1 + 1 + 1 + UI + 0 + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + + 1 + 1 + impl_virtual + + + 0 + wxID_ANY + + + EngineTabBF + + 500,300 + ; ; forward_declare + + 0 + + + wxTAB_TRAVERSAL + + + main_sizer + wxVERTICAL + none + + 5 + wxEXPAND + 0 + + + engine_name_sizer + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Name: + 0 + + 0 + + + 0 + + 1 + engine_name_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + engine_name + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + 5 + wxEXPAND + 0 + + + engine_location_sizer + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Location: + 0 + + 0 + + + 0 + + 1 + engine_location_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + engine_location + 1 + + + protected + 1 + + Resizable + 1 + + wxTE_READONLY + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + separator_1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + ; ; forward_declare + 0 + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Parameters: + 0 + + 0 + + + 0 + + 1 + params_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + + 1 + + 0 + 0 + wxID_ANY + 1 + + 0 + + + 0 + + 1 + engine_parameters + 1 + + + protected + 1 + + Resizable + 1 + + wxPG_DEFAULT_STYLE + ; ; forward_declare + 0 + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Save + + 0 + + 0 + + + 0 + + 1 + save_button + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + +