├── AUTHORS ├── .gitignore ├── src ├── fedit2.rc ├── fedit2.ico ├── Makefile.am ├── command.h ├── main.cpp ├── src.pro ├── config_dialog.h ├── constraint_edit_dialog.h ├── constraint_view.h ├── constraint_delegate.h ├── sample_view.h ├── coordinate_delegate.h ├── edit_dialog.h ├── mouse_state.h ├── command.cpp ├── edit_canvas.h ├── coordinate_delegate.cpp ├── constraint_delegate.cpp ├── constraint_edit_dialog.cpp ├── config_dialog.cpp ├── edit_data.h ├── main_window.h ├── options.h ├── constraint_view.cpp ├── options.cpp ├── sample_view.cpp └── edit_dialog.cpp ├── NEWS ├── reconfig.sh ├── tool ├── dttrainer │ ├── memo │ ├── Makefile.am │ ├── main.cpp │ ├── trainer.h │ └── trainer.cpp ├── Makefile.am ├── formation_converter.cpp └── average_formation.cpp ├── bootstrap ├── fedit2.pro ├── xpm ├── delete.xpm ├── train.xpm ├── symmetry.xpm ├── insert.xpm ├── chase.xpm ├── replace.xpm ├── reverse.xpm ├── hand.xpm ├── new.xpm ├── save.xpm ├── open.xpm ├── record.xpm └── fedit2.xpm ├── Makefile.am ├── m4 ├── ax_cxx_compile_stdcxx_14.m4 ├── ax_cxx_compile_stdcxx_17.m4 ├── qt.m4 ├── ax_boost_system.m4 └── ax_boost_base.m4 ├── README └── configure.ac /AUTHORS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | fedit2 2 | average_formation 3 | -------------------------------------------------------------------------------- /src/fedit2.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "fedit2.ico" 2 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helios-base/fedit2/HEAD/NEWS -------------------------------------------------------------------------------- /src/fedit2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helios-base/fedit2/HEAD/src/fedit2.ico -------------------------------------------------------------------------------- /reconfig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./bootstrap 4 | ./configure --prefix=$HOME/local 5 | 6 | -------------------------------------------------------------------------------- /tool/dttrainer/memo: -------------------------------------------------------------------------------- 1 | 2 | プログラム引数 3 | 学習パラメータ 4 | 重み 5 | ランダム初期化スイッチ 6 | フォーメーションファイル 7 | 訓練データファイル 8 | 9 | 10 | 収束の条件は設定する? 11 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if libtoolize --version > /dev/null 2>&1 ; then 4 | LIBTOOLIZE="libtoolize" 5 | elif glibtoolize --version > /dev/null 2>&1 ; then 6 | LIBTOOLIZE="glibtoolize" 7 | else 8 | echo "Error: libtoolize can not be found in you PATH" 9 | echo "" 10 | exit 1 11 | fi 12 | 13 | set -x 14 | autoreconf -i -f 15 | #aclocal -I config 16 | #$LIBTOOLIZE -f -c 17 | #aclocal -I config 18 | #autoheader 19 | #automake -a -c 20 | #autoconf 21 | -------------------------------------------------------------------------------- /fedit2.pro: -------------------------------------------------------------------------------- 1 | 2 | TEMPLATE = subdirs 3 | SUBDIRS = 4 | win32 { 5 | SUBDIRS += rcsc 6 | } 7 | SUBDIRS += src 8 | 9 | DISTFILES += \ 10 | xpm/chase.xpm \ 11 | xpm/delete.xpm \ 12 | xpm/hand.xpm \ 13 | xpm/insert.xpm \ 14 | xpm/new.xpm \ 15 | xpm/open.xpm \ 16 | xpm/record.xpm \ 17 | xpm/replace.xpm \ 18 | xpm/reverse.xpm \ 19 | xpm/save.xpm \ 20 | xpm/soccerwindow2-nostr.xpm \ 21 | xpm/soccerwindow2.xpm \ 22 | xpm/symmetry.xpm \ 23 | xpm/train.xpm 24 | -------------------------------------------------------------------------------- /tool/dttrainer/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | bin_PROGRAMS = dttrainer 4 | 5 | dttrainer_SOURCES = \ 6 | trainer.cpp \ 7 | main.cpp 8 | 9 | noinst_HEADERS = \ 10 | trainer.h 11 | 12 | dttrainer_CPPFLAGS = -I$(top_srcdir) 13 | dttrainer_CXXFLAGS = -Wall -W 14 | dttrainer_LDFLAGS = 15 | dttrainer_LDADD = 16 | 17 | AM_CPPFLAGS = 18 | AM_CFLAGS = -Wall -W 19 | AM_CXXFLAGS = -Wall -W 20 | AM_LDFLAGS = 21 | 22 | CLEANFILES = *~ 23 | -------------------------------------------------------------------------------- /xpm/delete.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * delete_xpm[] = { 3 | "16 16 2 1", 4 | " c None", 5 | ". c #000000", 6 | " ", 7 | " .. .. ", 8 | " ... ... ", 9 | " ... ... ", 10 | " ... ... ", 11 | " ... ... ", 12 | " ...... ", 13 | " .... ", 14 | " .... ", 15 | " ...... ", 16 | " ... ... ", 17 | " ... ... ", 18 | " ... ... ", 19 | " ... ... ", 20 | " .. .. ", 21 | " "}; 22 | -------------------------------------------------------------------------------- /xpm/train.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * train_xpm[] = { 3 | "16 16 2 1", 4 | " c None", 5 | ". c #000000", 6 | " . . ", 7 | " . . ", 8 | " . . ", 9 | " ... ... ", 10 | " ... ... ", 11 | " . . . . ", 12 | " . . . . ", 13 | " . . . . ", 14 | "... ... ... ", 15 | "... ... ... ", 16 | " . . . . ", 17 | " . . .. ", 18 | " ... ... ", 19 | " ... ... ", 20 | " . . ", 21 | " . . "}; 22 | -------------------------------------------------------------------------------- /xpm/symmetry.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * symmetry_xpm[] = { 3 | "16 16 3 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #FFFF00", 7 | " ... ", 8 | " .+++. ", 9 | " ... .+++. ", 10 | " .+++. .+++. ", 11 | " .+++. ... ", 12 | " .+++. ", 13 | " ... ", 14 | "................", 15 | " ... ", 16 | " .+++. ", 17 | " .+++. ... ", 18 | " .+++. .+++. ", 19 | " ... .+++. ", 20 | " .+++. ", 21 | " ... ", 22 | " "}; 23 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS=-I m4 2 | 3 | SUBDIRS = src tool 4 | 5 | LIBTOOL_DEPS = @LIBTOOL_DEPS@ 6 | libtool: $(LIBTOOL_DEPS) 7 | $(SHELL) ./config.status --recheck 8 | 9 | EXTRA_DIST = \ 10 | bootstrap \ 11 | fedit2.pro \ 12 | xpm/chase.xpm \ 13 | xpm/delete.xpm \ 14 | xpm/hand.xpm \ 15 | xpm/insert.xpm \ 16 | xpm/new.xpm \ 17 | xpm/open.xpm \ 18 | xpm/record.xpm \ 19 | xpm/replace.xpm \ 20 | xpm/reverse.xpm \ 21 | xpm/save.xpm \ 22 | xpm/fedit2.xpm \ 23 | xpm/symmetry.xpm \ 24 | xpm/train.xpm 25 | 26 | CLEANFILES = *~ 27 | -------------------------------------------------------------------------------- /xpm/insert.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * insert_xpm[] = { 3 | "16 15 5 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #808080", 7 | "@ c #FF0000", 8 | "# c #FFFFFF", 9 | " ", 10 | " ... ", 11 | " .+++.", 12 | " .+++.", 13 | " .+++.", 14 | " ... @ ... ", 15 | ".###. @@ ", 16 | ".###. @@@@@@ ", 17 | ".###. @@ ", 18 | " ... @ ... ", 19 | " .+++.", 20 | " .+++.", 21 | " .+++.", 22 | " ... ", 23 | " "}; 24 | -------------------------------------------------------------------------------- /xpm/chase.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * chase_xpm[] = { 3 | "16 16 4 1", 4 | " c None", 5 | ". c #FFFFFF", 6 | "+ c #404040", 7 | "@ c #EFEF00", 8 | " ...", 9 | " ...", 10 | " +++++...", 11 | " ++ ", 12 | " + + ", 13 | " + + ", 14 | " + + ", 15 | " + ", 16 | " @@ + ", 17 | " @@@@@@ ", 18 | " @@@@@@ ", 19 | "@@@@@@@@ ", 20 | "@@@@@@@@ ", 21 | " @@@@@@ ", 22 | " @@@@@@ ", 23 | " @@ "}; 24 | -------------------------------------------------------------------------------- /xpm/replace.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * replace_xpm[] = { 3 | "16 15 5 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #999999", 7 | "@ c #000080", 8 | "# c #FFFFFF", 9 | " ", 10 | " ...... ", 11 | " .++++.. ", 12 | " .++++.+. ", 13 | " .+..+.@@@@@@ ", 14 | " .+++++@####@@ ", 15 | " .+....@####@#@ ", 16 | " .+++++@#..#@@@@", 17 | " .+....@#######@", 18 | " .+++++@#.....#@", 19 | " ......@#######@", 20 | " @#.....#@", 21 | " @#######@", 22 | " @@@@@@@@@", 23 | " "}; 24 | -------------------------------------------------------------------------------- /xpm/reverse.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * reverse_xpm[] = { 3 | "16 15 5 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #FFFFFF", 7 | "@ c #FF0000", 8 | "# c #808080", 9 | " ... ", 10 | " .+++. ", 11 | " .+++. ", 12 | " .+++. ", 13 | " ... ", 14 | " @ ", 15 | " @ ", 16 | " @ ", 17 | " @@@ ", 18 | " @ ", 19 | " ... ", 20 | " .###. ", 21 | " .###. ", 22 | " .###. ", 23 | " ... "}; 24 | -------------------------------------------------------------------------------- /xpm/hand.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * hand_xpm[] = { 3 | "16 16 5 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #FFFFFF", 7 | "@ c #808080", 8 | "# c #C0C0C0", 9 | " ", 10 | " .. ", 11 | " .. .+@.. ", 12 | " .@+..+#.+. . ", 13 | " .+#.+@.+..#. ", 14 | " .+#.+#.+.+@. ", 15 | " .#.##+#++.##. ", 16 | " .+..++++++#+@. ", 17 | " .+#.+++++###. ", 18 | " +#++++#++#. ", 19 | " .+++++#+##@. ", 20 | " .+#++#+ +#. ", 21 | " .+#++ . ", 22 | " .+#+ . ", 23 | " . + . ", 24 | " "}; 25 | -------------------------------------------------------------------------------- /xpm/new.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char *new_xpm[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "16 15 3 1", 5 | " c None", 6 | ". c Black", 7 | "X c Gray100", 8 | /* pixels */ 9 | " ", 10 | " ........ ", 11 | " .XXXXXX.. ", 12 | " .XXXXXX.X. ", 13 | " .XXXXXX.... ", 14 | " .XXXXXXXXX. ", 15 | " .XXXXXXXXX. ", 16 | " .XXXXXXXXX. ", 17 | " .XXXXXXXXX. ", 18 | " .XXXXXXXXX. ", 19 | " .XXXXXXXXX. ", 20 | " .XXXXXXXXX. ", 21 | " .XXXXXXXXX. ", 22 | " ........... ", 23 | " " 24 | }; 25 | -------------------------------------------------------------------------------- /xpm/save.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char *save_xpm[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "16 15 4 1", 5 | " c None", 6 | ". c Black", 7 | "X c #808000", 8 | "o c #808080", 9 | /* pixels */ 10 | " ", 11 | " .............. ", 12 | " .X. . . ", 13 | " .X. ... ", 14 | " .X. .X. ", 15 | " .X. .X. ", 16 | " .X. .X. ", 17 | " .X. .X. ", 18 | " .XX........oX. ", 19 | " .XXXXXXXXXXXX. ", 20 | " .XX.........X. ", 21 | " .XX...... .X. ", 22 | " .XX...... .X. ", 23 | " .XX...... .X. ", 24 | " ............. " 25 | }; 26 | -------------------------------------------------------------------------------- /xpm/open.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char *open_xpm[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "16 15 5 1", 5 | " c None", 6 | ". c Black", 7 | "X c Yellow", 8 | "o c Gray100", 9 | "O c #bfbf00", 10 | /* pixels */ 11 | " ", 12 | " ... ", 13 | " . . .", 14 | " ..", 15 | " ... ...", 16 | " .XoX....... ", 17 | " .oXoXoXoXo. ", 18 | " .XoXoXoXoX. ", 19 | " .oXoX..........", 20 | " .XoX.OOOOOOOOO.", 21 | " .oo.OOOOOOOOO. ", 22 | " .X.OOOOOOOOO. ", 23 | " ..OOOOOOOOO. ", 24 | " ........... ", 25 | " " 26 | }; 27 | -------------------------------------------------------------------------------- /xpm/record.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * record_xpm[] = { 3 | "16 16 12 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #0C0000", 7 | "@ c #0F0000", 8 | "# c #140000", 9 | "$ c #100000", 10 | "% c #C80000", 11 | "& c #930000", 12 | "* c #0D0000", 13 | "= c #270000", 14 | "- c #200000", 15 | "; c #9A0000", 16 | " ", 17 | " ", 18 | " .+@#$. ", 19 | " .%%%%%%. ", 20 | " .%%%%%%%%$ ", 21 | " #%%%%%%%%%&. ", 22 | " *%%%%%%%%%%. ", 23 | " $%%%%%%%%%%# ", 24 | " .%%%%%%%%%%@ ", 25 | " .%%%%%%%%%%= ", 26 | " .%%%%%%%%%%- ", 27 | " .%%%%%%%;$ ", 28 | " .%%%%%%$ ", 29 | " ...#.. ", 30 | " ", 31 | " "}; 32 | -------------------------------------------------------------------------------- /tool/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | bin_PROGRAMS = average_formation formation_converter 4 | 5 | #SUBDIRS = dttrainer 6 | 7 | average_formation_SOURCES = \ 8 | average_formation.cpp 9 | 10 | formation_converter_SOURCES = \ 11 | formation_converter.cpp 12 | 13 | average_formation_CPPFLAGS = -I$(top_srcdir) 14 | average_formation_CXXFLAGS = -Wall -W 15 | average_formation_LDFLAGS = 16 | average_formation_LDADD = 17 | 18 | formation_converter_CPPFLAGS = -I$(top_srcdir) 19 | formation_converter_CXXFLAGS = -Wall -W 20 | formation_converter_LDFLAGS = 21 | formation_converter_LDADD = 22 | 23 | 24 | AM_CPPFLAGS = 25 | AM_CFLAGS = -Wall -W 26 | AM_CXXFLAGS = -Wall -W 27 | AM_LDFLAGS = 28 | 29 | 30 | CLEANFILES = *~ 31 | -------------------------------------------------------------------------------- /tool/formation_converter.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace rcsc; 10 | 11 | /*-------------------------------------------------------------------*/ 12 | /*! 13 | 14 | */ 15 | Formation::Ptr 16 | openFormation( const char * filepath ) 17 | { 18 | Formation::Ptr ptr = FormationParser::parse( filepath ); 19 | return ptr; 20 | 21 | } 22 | 23 | /*-------------------------------------------------------------------*/ 24 | /*! 25 | 26 | */ 27 | static 28 | void 29 | usage( const char * prog ) 30 | { 31 | std::cerr << prog << " FORMATION.CONF" << std::endl; 32 | } 33 | 34 | /*-------------------------------------------------------------------*/ 35 | /*! 36 | 37 | */ 38 | int 39 | main( int argc, char ** argv ) 40 | { 41 | if ( argc < 2 ) 42 | { 43 | usage( argv[0] ); 44 | return 1; 45 | } 46 | 47 | std::string filepath = argv[1]; 48 | 49 | Formation::Ptr f = FormationParser::parse( filepath ); 50 | 51 | if ( ! f ) 52 | { 53 | std::cerr << "Could not open the formation " << filepath << std::endl; 54 | return 1; 55 | } 56 | 57 | f->print( std::cout ); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /xpm/fedit2.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static const char * fedit2_xpm[] = { 3 | "32 32 4 1", 4 | " c None", 5 | ". c #009800", 6 | "+ c #FFFFFF", 7 | "@ c #000000", 8 | "................................", 9 | "................................", 10 | "................................", 11 | "................................", 12 | "................................", 13 | ".++++++++++++++++++++++++++++++.", 14 | ".+..............+.............+.", 15 | ".+..............+.............+.", 16 | ".+..............+.............+.", 17 | ".+..............+.............+.", 18 | ".+++++..........+.........+++++.", 19 | ".+...+..........+.........+...+.", 20 | ".+...+..........+.........+...+.", 21 | ".+...+.........+++........+...+.", 22 | "@@...+........+.+.+.......+...@@", 23 | "@@...+.......+..+..+......+...@@", 24 | "@@...+.......+..+..+......+...@@", 25 | "@@...+........+.+.+.......+...@@", 26 | ".+...+.........+++........+...+.", 27 | ".+...+..........+.........+...+.", 28 | ".+...+..........+.........+...+.", 29 | ".+++++..........+.........+++++.", 30 | ".+..............+.............+.", 31 | ".+..............+.............+.", 32 | ".+..............+.............+.", 33 | ".+..............+.............+.", 34 | ".++++++++++++++++++++++++++++++.", 35 | "................................", 36 | "................................", 37 | "................................", 38 | "................................", 39 | "................................"}; 40 | -------------------------------------------------------------------------------- /m4/ax_cxx_compile_stdcxx_14.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_14.html 3 | # ============================================================================= 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_COMPILE_STDCXX_14([ext|noext], [mandatory|optional]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check for baseline language coverage in the compiler for the C++14 12 | # standard; if necessary, add switches to CXX and CXXCPP to enable 13 | # support. 14 | # 15 | # This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX 16 | # macro with the version set to C++14. The two optional arguments are 17 | # forwarded literally as the second and third argument respectively. 18 | # Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for 19 | # more information. If you want to use this macro, you also need to 20 | # download the ax_cxx_compile_stdcxx.m4 file. 21 | # 22 | # LICENSE 23 | # 24 | # Copyright (c) 2015 Moritz Klammler 25 | # 26 | # Copying and distribution of this file, with or without modification, are 27 | # permitted in any medium without royalty provided the copyright notice 28 | # and this notice are preserved. This file is offered as-is, without any 29 | # warranty. 30 | 31 | #serial 5 32 | 33 | AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) 34 | AC_DEFUN([AX_CXX_COMPILE_STDCXX_14], [AX_CXX_COMPILE_STDCXX([14], [$1], [$2])]) 35 | -------------------------------------------------------------------------------- /m4/ax_cxx_compile_stdcxx_17.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html 3 | # ============================================================================= 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check for baseline language coverage in the compiler for the C++17 12 | # standard; if necessary, add switches to CXX and CXXCPP to enable 13 | # support. 14 | # 15 | # This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX 16 | # macro with the version set to C++17. The two optional arguments are 17 | # forwarded literally as the second and third argument respectively. 18 | # Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for 19 | # more information. If you want to use this macro, you also need to 20 | # download the ax_cxx_compile_stdcxx.m4 file. 21 | # 22 | # LICENSE 23 | # 24 | # Copyright (c) 2015 Moritz Klammler 25 | # Copyright (c) 2016 Krzesimir Nowak 26 | # 27 | # Copying and distribution of this file, with or without modification, are 28 | # permitted in any medium without royalty provided the copyright notice 29 | # and this notice are preserved. This file is offered as-is, without any 30 | # warranty. 31 | 32 | #serial 2 33 | 34 | AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) 35 | AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])]) 36 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | bin_PROGRAMS = fedit2 4 | 5 | fedit2_SOURCES = \ 6 | command.cpp \ 7 | config_dialog.cpp \ 8 | coordinate_delegate.cpp \ 9 | edit_canvas.cpp \ 10 | edit_data.cpp \ 11 | edit_dialog.cpp \ 12 | sample_view.cpp \ 13 | main_window.cpp \ 14 | options.cpp \ 15 | main.cpp 16 | 17 | 18 | # constraint_delegate.cpp 19 | # constraint_edit_dialog.cpp 20 | # constraint_view.cpp 21 | 22 | 23 | noinst_HEADERS = \ 24 | mouse_state.h \ 25 | command.h \ 26 | config_dialog.h \ 27 | coordinate_delegate.h \ 28 | edit_canvas.h \ 29 | edit_data.h \ 30 | edit_dialog.h \ 31 | sample_view.h \ 32 | main_window.h \ 33 | options.h 34 | 35 | # constraint_delegate.h 36 | # constraint_edit_dialog.h 37 | # constraint_view.h 38 | 39 | 40 | nodist_fedit2_SOURCES = \ 41 | moc_config_dialog.cpp \ 42 | moc_coordinate_delegate.cpp \ 43 | moc_edit_dialog.cpp \ 44 | moc_edit_canvas.cpp \ 45 | moc_sample_view.cpp \ 46 | moc_main_window.cpp 47 | 48 | # moc_constraint_delegate.cpp 49 | # moc_constraint_edit_dialog.cpp 50 | # moc_constraint_view.cpp 51 | 52 | 53 | fedit2_CPPFLAGS = -I$(top_srcdir) $(QT_CPPFLAGS) 54 | fedit2_CXXFLAGS = $(QT_CXXFLAGS) -Wall -W -Wno-deprecated-copy 55 | fedit2_LDFLAGS = $(QT_LDFLAGS) 56 | fedit2_LDADD = $(QT_LDADD) 57 | 58 | # source files from headers generated by Meta Object Compiler 59 | moc_%.cpp: %.h 60 | $(QT_MOC) $< -o $@ 61 | 62 | AM_CPPFLAGS = 63 | AM_CFLAGS = -Wall -W 64 | AM_CXXFLAGS = -Wall -W 65 | AM_LDFLAGS = 66 | 67 | EXTRA_DIST = \ 68 | src.pro \ 69 | fedit2.rc \ 70 | fedit2.ico 71 | 72 | 73 | CLEANFILES = $(nodist_fedit2_SOURCES) *~ 74 | -------------------------------------------------------------------------------- /src/command.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file command.h 5 | \brief edit command class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_COMMAND_H 33 | #define FEDIT2_COMMAND_H 34 | 35 | #include 36 | #include 37 | 38 | class EditScene; 39 | 40 | class QGraphicsItem; 41 | 42 | class MoveCommand 43 | : public QUndoCommand { 44 | private: 45 | 46 | QPointF M_old_pos; 47 | QPointF M_new_pos; 48 | 49 | public: 50 | 51 | MoveCommand( const QPointF & old_pos, 52 | const QPointF & new_pos, 53 | QUndoCommand * parent = 0 ); 54 | ~MoveCommand(); 55 | 56 | int id() const 57 | { 58 | return 1; 59 | } 60 | 61 | void undo(); 62 | void redo(); 63 | // bool mergeWith( const QUndoCommand * command ); 64 | 65 | private: 66 | 67 | void updateText(); 68 | 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file main.cpp 5 | \brief main() source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #include "main_window.h" 39 | #include "options.h" 40 | 41 | #include 42 | 43 | int 44 | main( int argc, char ** argv ) 45 | { 46 | std::cout << "******************************************************************\n" 47 | << " " PACKAGE " " VERSION "\n" 48 | << " Copyright: (C) 2013. Hidehisa Akiyama\n" 49 | << " All rights reserved.\n" 50 | << "******************************************************************\n" 51 | << std::endl; 52 | 53 | QApplication app( argc, argv ); 54 | 55 | if ( ! Options::instance().parseCmdLine( argc, argv ) ) 56 | { 57 | return 1; 58 | } 59 | 60 | MainWindow win; 61 | win.show(); 62 | win.init(); 63 | 64 | return app.exec(); 65 | } 66 | -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | 2 | TEMPLATE = app 3 | TARGET = fedit2 4 | DESTDIR = ../bin 5 | 6 | win32 { 7 | DEPENDPATH += ../rcsc 8 | } 9 | 10 | INCLUDEPATH += . .. 11 | win32 { 12 | INCLUDEPATH += ../boost 13 | } 14 | unix { 15 | INCLUDEPATH += ${HOME}/local/include 16 | INCLUDEPATH += /opt/local/include 17 | } 18 | macx { 19 | INCLUDEPATH += /opt/local/include 20 | } 21 | 22 | win32 { 23 | LIBS += -L../lib 24 | LIBS += -lrcsc ../zlib/zlib1.dll -lwsock32 25 | } 26 | unix { 27 | LIBS += -L${HOME}/local/lib 28 | LIBS += -lrcsc_agent -lrcsc_time -lrcsc_ann -lrcsc_param -lrcsc_net -lrcsc_gz -lrcsc_rcg -lrcsc_geom -lz 29 | } 30 | 31 | DEFINES += HAVE_LIBRCSC_GZ 32 | win32 { 33 | DEFINES += HAVE_WINDOWS_H NO_TIMER 34 | } 35 | unix { 36 | DEFINES += HAVE_NETINET_IN_H 37 | } 38 | DEFINES += PACKAGE="\\\"fedit2\\\"" VERSION="\\\"0.0.0\\\"" 39 | 40 | CONFIG += qt warn_on release 41 | win32 { 42 | CONFIG += windows 43 | } 44 | 45 | QMAKE_CXXFLAGS += -static 46 | 47 | # Input 48 | HEADERS += \ 49 | command.h \ 50 | constraint_delegate.h \ 51 | constraint_edit_dialog.h \ 52 | constraint_view.h \ 53 | coordinate_delegate.h \ 54 | edit_canvas.h \ 55 | edit_data.h \ 56 | edit_dialog.h \ 57 | main_window.h \ 58 | mouse_state.h \ 59 | options.h \ 60 | sample_view.h 61 | 62 | SOURCES += \ 63 | command.cpp \ 64 | constraint_delegate.cpp \ 65 | constraint_edit_dialog.cpp \ 66 | constraint_view.cpp \ 67 | coordinate_delegate.cpp \ 68 | edit_canvas.cpp \ 69 | edit_data.cpp \ 70 | edit_dialog.cpp \ 71 | main.cpp \ 72 | main_window.cpp \ 73 | options.cpp \ 74 | sample_view.cpp \ 75 | 76 | nodist_soccerwindow2_qt4_SOURCES = \ 77 | moc_constraint_delegate.cpp \ 78 | moc_constraint_edit_dialog.cpp \ 79 | moc_constraint_view.cpp \ 80 | moc_coordinate_delegate.cpp \ 81 | moc_edit_canvas.cpp \ 82 | moc_edit_dialog.cpp \ 83 | moc_main_window.cpp \ 84 | moc_sample_view.cpp 85 | 86 | RC_FILE = fedit2.rc 87 | -------------------------------------------------------------------------------- /src/config_dialog.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file config_dialog.h 5 | \brief Config Dialog class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 3, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef CONFIG_DIALOG_H 33 | #define CONFIG_DIALOG_H 34 | 35 | #include 36 | 37 | class QLineEdit; 38 | 39 | class ConfigDialog 40 | : public QDialog { 41 | 42 | Q_OBJECT 43 | 44 | private: 45 | 46 | // canvas size control 47 | QLineEdit * M_view_width_text; 48 | QLineEdit * M_view_height_text; 49 | QLineEdit * M_scale_text; 50 | 51 | public: 52 | 53 | explicit 54 | ConfigDialog( QWidget * parent ); 55 | ~ConfigDialog(); 56 | 57 | private: 58 | 59 | void createWidgets(); 60 | QWidget * createViewSizeControls(); 61 | QWidget * createViewScaleControls(); 62 | 63 | protected: 64 | 65 | void showEvent( QShowEvent * event ); 66 | void closeEvent( QCloseEvent * event ); 67 | 68 | private slots: 69 | 70 | void updateAll(); 71 | 72 | void applyViewSize(); 73 | void editViewScale( const QString & text ); 74 | 75 | signals: 76 | 77 | void viewResizeApplied( const QSize & size ); 78 | void configured(); 79 | void shown( bool on ); 80 | 81 | }; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /tool/dttrainer/main.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /* 4 | *Copyright: 5 | 6 | Copyright (C) Hidehisa AKIYAMA 7 | 8 | This code is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2, or (at your option) 11 | any later version. 12 | 13 | This code is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this code; see the file COPYING. If not, write to 20 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | *EndCopyright: 23 | */ 24 | 25 | ///////////////////////////////////////////////////////////////////// 26 | 27 | #ifdef HAVE_CONFIG_H 28 | #include 29 | #endif 30 | 31 | #include "trainer.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | int 38 | main( int argc, 39 | char ** argv ) 40 | { 41 | Trainer trainer; 42 | 43 | std::string formation_conf; 44 | std::string training_data; 45 | 46 | if ( argc < 3 ) 47 | { 48 | std::cerr << "Usage: " 49 | << argv[0] << " " 50 | << std::endl; 51 | return 1; 52 | } 53 | 54 | formation_conf = argv[1]; 55 | training_data = argv[2]; 56 | 57 | if ( ! trainer.readFormation( formation_conf ) ) 58 | { 59 | std::cerr << "ERROR: readFormation" << std::endl; 60 | return 1; 61 | } 62 | 63 | if ( ! trainer.readTrainingData( training_data ) ) 64 | { 65 | std::cerr << "ERROR: readTrainingData" << std::endl; 66 | return 1; 67 | } 68 | 69 | std::cerr << "start" << std::endl; 70 | trainer.train(); 71 | 72 | { 73 | std::string result_conf = "result.conf"; 74 | std::ofstream fout( result_conf.c_str() ); 75 | trainer.printFormation( fout ); 76 | } 77 | std::cerr << "finished all" << std::endl; 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /src/constraint_edit_dialog.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file constraint_edit_dialog.h 5 | \brief Formation editor position edit Dialog class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_CONSTRAINT_EDIT_DIALOG_H 33 | #define FEDIT2_CONSTRAINT_EDIT_DIALOG_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | class EditCanvas; 40 | class EditData; 41 | 42 | class QSpinBox; 43 | 44 | /*! 45 | \class EditDialog 46 | \brief formation editor position edit dialog 47 | */ 48 | class ConstraintEditDialog 49 | : public QDialog { 50 | 51 | Q_OBJECT; 52 | 53 | private: 54 | 55 | EditCanvas * M_edit_canvas; 56 | std::shared_ptr< EditData > M_edit_data; 57 | 58 | QSpinBox * M_origin; 59 | QSpinBox * M_terminal; 60 | 61 | // not used 62 | ConstraintEditDialog(); 63 | ConstraintEditDialog( const ConstraintEditDialog & ); 64 | ConstraintEditDialog & operator=( const ConstraintEditDialog & ); 65 | public: 66 | 67 | ConstraintEditDialog( QWidget * parent, 68 | EditCanvas * canvas, 69 | std::shared_ptr< EditData > data, 70 | const int origin_index, 71 | const int terminal_index ); 72 | ~ConstraintEditDialog(); 73 | 74 | int originIndex() const; 75 | int terminalIndex() const; 76 | 77 | private: 78 | 79 | void createWidgets(); 80 | 81 | 82 | private slots: 83 | 84 | void changeIndex(); 85 | 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/constraint_view.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file constraint_view.h 5 | \brief constraint view class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_CONSTRAINT_VIEW_H 33 | #define FEDIT2_CONSTRAINT_VIEW_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | class ConstraintDelegate; 40 | class EditData; 41 | 42 | class ConstraintView 43 | : public QTableWidget { 44 | 45 | Q_OBJECT 46 | 47 | private: 48 | 49 | std::weak_ptr< EditData > M_edit_data; 50 | 51 | ConstraintDelegate * M_origin_delegate; 52 | ConstraintDelegate * M_terminal_delegate; 53 | 54 | public: 55 | 56 | ConstraintView( QWidget * parent = 0 ); 57 | ~ConstraintView(); 58 | 59 | void setData( std::shared_ptr< EditData > ptr ) 60 | { 61 | M_edit_data = ptr; 62 | } 63 | 64 | void updateData(); 65 | 66 | protected: 67 | 68 | void contextMenuEvent( QContextMenuEvent * event ); 69 | 70 | private slots: 71 | 72 | void setCurrentData( QTableWidgetItem * current ); 73 | void menuDeleteConstraint(); 74 | void changeConstraintIndex( const QModelIndex & index, 75 | int value ); 76 | 77 | signals: 78 | 79 | void constraintSelected( int idx ); 80 | void constraintDeleteRequested( int origin_idx, 81 | int terminal_idx ); 82 | void constraintReplaced( int idx, 83 | int origin_idx, 84 | int terminal_idx ); 85 | 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/constraint_delegate.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file constraint_delegate.h 5 | \brief constraint index editor delegate class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_CONSTRAINT_DELEGATE_H 33 | #define FEDIT2_CONSTRAINT_DELEGATE_H 34 | 35 | 36 | #include 37 | 38 | class QModelIndex; 39 | 40 | class ConstraintDelegate 41 | : public QItemDelegate { 42 | 43 | Q_OBJECT 44 | 45 | private: 46 | 47 | int M_minimum; 48 | int M_maximum; 49 | public: 50 | 51 | ConstraintDelegate( QObject * parent = 0 ); 52 | ~ConstraintDelegate(); 53 | 54 | void setRange( const int minimum, 55 | const int maximum ); 56 | 57 | virtual 58 | QWidget * createEditor( QWidget * parent, 59 | const QStyleOptionViewItem & option, 60 | const QModelIndex & index ) const; 61 | virtual 62 | void setEditorData( QWidget * editor, 63 | const QModelIndex & index ) const; 64 | virtual 65 | void setModelData( QWidget * editor, 66 | QAbstractItemModel * model, 67 | const QModelIndex & index ) const; 68 | virtual 69 | void updateEditorGeometry( QWidget * editor, 70 | const QStyleOptionViewItem & option, 71 | const QModelIndex & index ) const; 72 | 73 | signals: 74 | 75 | void valueChanged( const QModelIndex & index, 76 | int value ) const; 77 | }; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /tool/dttrainer/trainer.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file trainer.h 5 | \brief trainer for FormationDT Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_TRAINER_H 33 | #define FEDIT2_TRAINER_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | #include 40 | 41 | class Trainer { 42 | public: 43 | 44 | struct Data { 45 | rcsc::Vector2D ball_; 46 | int unum_; 47 | rcsc::Vector2D pos_; 48 | 49 | Data( const double bx, 50 | const double by, 51 | const int unum, 52 | const double px, 53 | const double py ) 54 | : ball_( bx, by ), 55 | unum_( unum ), 56 | pos_( px, py ) 57 | { } 58 | }; 59 | 60 | 61 | private: 62 | 63 | rcsc::FormationDT M_formation; //!< target formation 64 | std::vector< rcsc::formation::SampleData > M_target_data; 65 | 66 | std::vector< Data > M_training_data; 67 | 68 | double M_alpha; //!< learning rate 69 | double M_error_thr; 70 | int M_max_loop; 71 | 72 | public: 73 | 74 | Trainer(); 75 | 76 | bool readFormation( const std::string & filepath ); 77 | bool readTrainingData( const std::string & filepath ); 78 | std::ostream & printFormation( std::ostream & os ) const; 79 | 80 | void train(); 81 | 82 | private: 83 | /*! 84 | \return error value. negative value is returned if update process failed 85 | */ 86 | double train( const Data & data ); 87 | 88 | }; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/sample_view.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file sample_view.h 5 | \brief sample data view class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_SAMPLE_VIEW_H 33 | #define FEDIT2_SAMPLE_VIEW_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | class EditData; 40 | 41 | class SampleView 42 | : public QTreeWidget { 43 | 44 | Q_OBJECT 45 | 46 | private: 47 | 48 | std::weak_ptr< EditData > M_edit_data; 49 | 50 | public: 51 | 52 | SampleView( QWidget * parent = 0 ); 53 | ~SampleView(); 54 | 55 | void setData( std::shared_ptr< EditData > ptr ) 56 | { 57 | M_edit_data = ptr; 58 | } 59 | 60 | 61 | void updateData(); 62 | 63 | void selectSample( int idx ); 64 | void unselectData(); 65 | 66 | protected: 67 | 68 | void contextMenuEvent( QContextMenuEvent * event ); 69 | void dropEvent( QDropEvent * event ); 70 | 71 | private slots: 72 | 73 | void setCurrentData( QTreeWidgetItem * current ); 74 | void menuChangeSampleIndex(); 75 | void menuDeleteSample(); 76 | void changeCoordinates( const QModelIndex & index, 77 | double value ); 78 | 79 | signals: 80 | 81 | void sampleSelected( int idx ); 82 | void sampleIndexChangeRequested( int old_visual_index, 83 | int new_visual_index ); 84 | void sampleDeleteRequested( int idx ); 85 | 86 | void ballReplaced( int idx, double x, double y ); 87 | void playerReplaced( int idx, int unum, double x, double y ); 88 | 89 | }; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/coordinate_delegate.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file coordinate_delegate.h 5 | \brief coordinate value editor delegate class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_COORDINATE_DELEGATE_H 33 | #define FEDIT2_COORDINATE_DELEGATE_H 34 | 35 | 36 | #include 37 | 38 | class QModelIndex; 39 | 40 | class CoordinateDelegate 41 | : public QItemDelegate { 42 | 43 | Q_OBJECT 44 | 45 | private: 46 | 47 | const double M_minimum; 48 | const double M_maximum; 49 | public: 50 | 51 | CoordinateDelegate( const double & mininum, 52 | const double & maximum, 53 | QObject * parent = 0 ); 54 | ~CoordinateDelegate(); 55 | 56 | virtual 57 | QWidget * createEditor( QWidget * parent, 58 | const QStyleOptionViewItem & option, 59 | const QModelIndex & index ) const; 60 | virtual 61 | void setEditorData( QWidget * editor, 62 | const QModelIndex & index ) const; 63 | virtual 64 | void setModelData( QWidget * editor, 65 | QAbstractItemModel * model, 66 | const QModelIndex & index ) const; 67 | virtual 68 | void updateEditorGeometry( QWidget * editor, 69 | const QStyleOptionViewItem & option, 70 | const QModelIndex & index ) const; 71 | 72 | signals: 73 | 74 | void valueChanged( const QModelIndex & index, 75 | double value ) const; 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/edit_dialog.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file edit_dialog.h 5 | \brief position edit Dialog class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_EDIT_DIALOG_H 33 | #define FEDIT2_EDIT_DIALOG_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | class QCheckBox; 40 | class QCloseEvent; 41 | class QComboBox; 42 | class QShowEvent; 43 | class QLineEdit; 44 | 45 | class EditData; 46 | 47 | /*! 48 | \class EditDialog 49 | \brief formation editor position edit dialog 50 | */ 51 | class EditDialog 52 | : public QDialog { 53 | 54 | Q_OBJECT; 55 | 56 | private: 57 | 58 | std::weak_ptr< EditData > M_edit_data; 59 | 60 | QLineEdit * M_type_name; //! formation method type 61 | 62 | QLineEdit * M_ball_pos_x; 63 | QLineEdit * M_ball_pos_y; 64 | 65 | QLineEdit * M_paired_number[11]; 66 | QComboBox * M_role_type[11]; 67 | QComboBox * M_role_side[11]; 68 | QLineEdit * M_role_name[11]; 69 | // QCheckBox * M_marker[11]; 70 | // QCheckBox * M_setplay_marker[11]; 71 | 72 | QLineEdit * M_pos_x[11]; 73 | QLineEdit * M_pos_y[11]; 74 | 75 | // not used 76 | EditDialog(); 77 | EditDialog( const EditDialog & ); 78 | EditDialog & operator=( const EditDialog & ); 79 | public: 80 | 81 | EditDialog( QWidget * paremt ); 82 | ~EditDialog(); 83 | 84 | void setData( std::shared_ptr< EditData > ptr ) 85 | { 86 | M_edit_data = ptr; 87 | } 88 | 89 | private: 90 | void createWidgets(); 91 | 92 | bool checkConsistency(); 93 | 94 | protected: 95 | void showEvent( QShowEvent * event ); 96 | void closeEvent( QCloseEvent * event ); 97 | 98 | private slots: 99 | void validateBallCoordinate(); 100 | void resetChanges(); 101 | void applyToField(); 102 | 103 | public slots: 104 | void updateData(); 105 | 106 | signals: 107 | void viewUpdated(); 108 | void shown( bool on ); 109 | }; 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /src/mouse_state.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file mouse_state.h 5 | \brief mouse state class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_MOUSE_STATE_H 33 | #define FEDIT2_MOUSE_STATE_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | class MouseState { 40 | private: 41 | 42 | bool M_pressed; 43 | bool M_menu_failed; 44 | QPoint M_pressed_point; 45 | QPoint M_dragged_point; 46 | 47 | public: 48 | MouseState() 49 | : M_pressed( false ) 50 | , M_menu_failed( false ) 51 | , M_pressed_point( 0, 0 ) 52 | , M_dragged_point( 0, 0 ) 53 | { } 54 | 55 | 56 | void pressed( const QPoint & point ) 57 | { 58 | M_pressed = true; 59 | M_pressed_point = M_dragged_point = point; 60 | } 61 | 62 | void released() 63 | { 64 | M_pressed = false; 65 | } 66 | 67 | void setMenuFailed( const bool value ) 68 | { 69 | M_menu_failed = value; 70 | } 71 | 72 | void moved( const QPoint & point ) 73 | { 74 | if ( M_pressed ) 75 | { 76 | M_dragged_point = point; 77 | } 78 | } 79 | 80 | bool isPressed() const 81 | { 82 | return M_pressed; 83 | } 84 | 85 | bool isMenuFailed() const 86 | { 87 | return M_menu_failed; 88 | } 89 | 90 | const 91 | QPoint & pressedPoint() const 92 | { 93 | return M_pressed_point; 94 | } 95 | 96 | const 97 | QPoint & draggedPoint() const 98 | { 99 | return M_dragged_point; 100 | } 101 | 102 | bool isDragged() const 103 | { 104 | return ( M_pressed 105 | && ( M_pressed_point - M_dragged_point ).manhattanLength() > 4 106 | // && ( qAbs( M_pressed_point.x() - M_dragged_point.x() ) > 2 107 | // || qAbs( M_pressed_point.y() - M_dragged_point.y() ) > 2 ) 108 | ); 109 | } 110 | 111 | }; 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | fedit2 is no longer maintained. 2 | The feature of the formation editor is integrated into soccerwindow2. 3 | Please use https://github.com/helios-base/soccerwindow2 instead. 4 | 5 | 6 | ============ 7 | はじめに 8 | ============ 9 | fedit2はRoboCupサッカーシミュレーションのためのフォーメーションエディ 10 | タです. 11 | 12 | - RoboCup Soccer Simulator Homepage: http://sserver.sf.net/ 13 | - RoboCup Official Homepage: http://www.robocup.org/ 14 | 15 | - fedit2 Homepage: http://rctools.sourceforge.jp/ 16 | 17 | ========== 18 | REFERENCES 19 | ========== 20 | 論文等での参照先としては以下をご利用ください. 21 | 22 | Hidehisa Akiyama, Tomoharu Nakashima, HELIOS Base: An Open Source 23 | Package for the RoboCup Soccer 2D Simulation, In Sven Behnke, Manuela 24 | Veloso, Arnoud Visser, and Rong Xiong editors, RoboCup2013: Robot 25 | World XVII, Lecture Notes in Artificial Intelligence, Springer Verlag, 26 | Berlin, 2014. 27 | 28 | @inbook{akiyama2014, 29 | author="Hidehisa AKIYAMA and Tomoharu NAKASHIMA", 30 | editor="Sven Behnke and Manuela Veloso and Arnoud Visser and Rong Xiong", 31 | title="HELIOS Base: An Open Source Package for the RoboCup Soccer 2D Simulation", 32 | booktitle="RoboCup 2013: Robot World Cup XVII", 33 | series="Lecture Notes in Artificial Intelligence", 34 | year="2014", 35 | publisher="Springer", 36 | address="Berlin", 37 | pages="528--535", 38 | isbn="978-3-662-44468-9", 39 | doi="10.1007/978-3-662-44468-9_46", 40 | url="http://dx.doi.org/10.1007/978-3-662-44468-9_46" 41 | } 42 | 43 | ============ 44 | 要求ライブラリ 45 | ============ 46 | fedit2-0.0.0 は以下のライブラリを要求します: 47 | - Qt-4.3 or later 48 | - boost-1.32 or later 49 | - librcsc-4.0.x 50 | 51 | fedit2のインストールを始める前に,これらのライブラリを先にインストール 52 | しておいてください. 53 | 54 | ========== 55 | インストール 56 | ========== 57 | パッケージを展開したディレクトリ内部で以下のコマンドを実行します: 58 | 59 | ./configure 60 | make 61 | su 62 | make install 63 | 64 | この手順によって必要なバイナリが生成され,それらは'/usr/local'以下へイ 65 | ンストールされます.'/usr/local/bin/fedit2'が実行ファイルです. 66 | 67 | librcscをシステムのディレクトリにインストールしていない場合,以下のよ 68 | うにconfigureの'--with-librcsc'オプションによってlibrcscのインストール 69 | パスを指定しなければなりません. 70 | 71 | ./configure --with-librcsc=/path/to/librcsc/prefix 72 | 73 | この場合,環境変数 LD_LIBRARY_PATH も設定する必要があるかもしれません. 74 | 75 | ================= 76 | インストール時の設定 77 | ================= 78 | fedit2をビルドする前に,パッケージに含まれるconfigureスクリプト 79 | のオプションによって設定を変更することができます. 80 | 81 | デフォルトの設定では,fedit2は以下の場所へインストールされます. 82 | 83 | /usr/local/bin 実行ファイル 84 | 85 | /usr/local/share データ 86 | 87 | デフォルト位置へfedit2をインストールするためには管理者権限が必要になり 88 | ます.インストール場所はconfigureスクリプトの'--prefix'オプションによっ 89 | て変更できます.configureで指定できるオプションの詳細は,'configure 90 | --help'を実行することで参照できます. 91 | 92 | ============= 93 | アンインストール 94 | ============= 95 | パッケージをコンパイルしたディレクトリで 'make uninstall'を実行するだ 96 | けでfedit2を簡単にアンインストールできます.この操作はインストールされ 97 | たすべてのファイルを削除しますが,インストール時に作成されたディレクト 98 | リは削除されません. 99 | 100 | ======= 101 | 使用方法 102 | ======= 103 | fedit2を実行するには,以下のコマンドを実行します. 104 | 105 | `fedit2' 106 | 107 | ただし,この場合,実行ファイルが環境変数PATHに含まれるディレクトリに存 108 | 在しなければなりません. 109 | -------------------------------------------------------------------------------- /m4/qt.m4: -------------------------------------------------------------------------------- 1 | 2 | # SYNOPSIS 3 | # 4 | # AX_QT [--with-qt4-moc=PATH] [--with-qt5-moc=PATH] 5 | # 6 | # DESCRIPTION 7 | # 8 | # The following shell variable is set to either "yes" or "no": 9 | # 10 | # have_qt 11 | # 12 | # Additionally, the following variables are exported: 13 | # 14 | # QT_CFLAGS 15 | # QT_CXXFLAGS 16 | # QT_LDFLAGS 17 | # QT_LDADD 18 | # QT_MOC 19 | # 20 | 21 | AC_DEFUN([AX_QT], 22 | [ 23 | AC_REQUIRE([AC_PROG_CXX]) 24 | AC_REQUIRE([AC_PATH_X]) 25 | AC_REQUIRE([AC_PATH_XTRA]) 26 | 27 | QT_REQUIRED_VERSION=ifelse([$1], ,4.1.0,$1) 28 | QT_REQUIRED_MODULES=ifelse([$2], ,QtCore,"$2") 29 | 30 | QT_MAJOR_VERSION=`echo $QT_REQUIRED_VERSION | cut -d . -f 1` 31 | 32 | AC_MSG_NOTICE([set QT_REQUIRED_VERSION... $QT_REQUIRED_VERSION]) 33 | AC_MSG_NOTICE([set QT_MAJOR_VERSION... $QT_MAJOR_VERSION]) 34 | AC_MSG_NOTICE([set QT_REQUIRED_MODULES... $QT_REQUIRED_MODULES]) 35 | 36 | 37 | 38 | # if "x$QT_REQUIRED_MODULES" = "x" ; then 39 | # AC_MSG_ERROR([No Qt modules]) 40 | # fi 41 | 42 | AC_PATH_PROG(PKG_CONFIG, pkg-config, no) 43 | if test "x$PKG_CONFIG" = "xno"; then 44 | AC_MSG_ERROR(You have to install pkg-config to compile $PACKAGENAME-$VERSION.) 45 | fi 46 | 47 | for mod in $QT_REQUIRED_MODULES ; do 48 | AC_MSG_NOTICE(check $mod >= $QT_REQUIRED_VERSION) 49 | PKG_CHECK_MODULES(QT, 50 | $mod >= $QT_REQUIRED_VERSION, 51 | have_qt="yes", 52 | have_qt="no") 53 | if test "$have_qt" = "no"; then 54 | AC_MSG_ERROR( 55 | [The $mod library >= [$QT_REQUIRED_VERSION] could not be found.]) 56 | fi 57 | done 58 | 59 | QT_CFLAGS=$($PKG_CONFIG --cflags $QT_REQUIRED_MODULES) 60 | QT_CXXFLAGS="$QT_CFLAGS" 61 | QT_CPPFLAGS="" 62 | QT_LDFLAGS=$($PKG_CONFIG --static --libs-only-L $QT_REQUIRED_MODULES) 63 | QT_LDADD="$($PKG_CONFIG --static --libs-only-other $QT_REQUIRED_MODULES) $($PKG_CONFIG --static --libs-only-l $QT_REQUIRED_MODULES)" 64 | AC_MSG_NOTICE([set QT_CXXFLAGS... $QT_CXXFLAGS]) 65 | AC_MSG_NOTICE([set QT_LDFLAGS... $QT_LDFLAGS]) 66 | AC_MSG_NOTICE([set QT_LDADD... $QT_LDADD]) 67 | AC_SUBST(QT_CFLAGS) 68 | AC_SUBST(QT_CXXFLAGS) 69 | AC_SUBST(QT_CPPFLAGS) 70 | AC_SUBST(QT_LDFLAGS) 71 | AC_SUBST(QT_LDADD) 72 | 73 | # check the path to moc 74 | QT_MOC="" 75 | 76 | AC_ARG_WITH([qt-moc], 77 | [ --with-qt-moc=PATH Qt's moc utilitiy to be used (optional)]) 78 | if test x$with_qt_moc != x && test -x "$with_qt_moc" ; then 79 | QT_MOC="$with_qt_moc" 80 | fi 81 | 82 | # AC_CHECK_PROG(QT_MOC, [moc], [moc]) 83 | 84 | if test x$QT_MOC = x ; then 85 | moc_bin=moc 86 | if test $QT_MAJOR_VERSION -eq 4 ; then 87 | moc_bin=moc-qt4 88 | fi 89 | 90 | for qt_path_tmp in /opt/local /usr/local /usr ; do 91 | if test -x "${qt_path_tmp}/bin/${moc_bin}" ; then 92 | QT_MOC="${qt_path_tmp}/bin/${moc_bin}" 93 | break; 94 | fi 95 | done 96 | fi 97 | if test x$QT_MOC = x ; then 98 | have_qt=no 99 | AC_MSG_ERROR([You must specify the path to Qt's moc command.]) 100 | fi 101 | 102 | AC_MSG_NOTICE([set QT_MOC... $QT_MOC]) 103 | AC_SUBST(QT_MOC) 104 | ]) 105 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.61) 5 | AC_INIT(fedit2, [2023], akky@users.sourceforge.jp) 6 | 7 | AC_CONFIG_SRCDIR([config.h.in]) 8 | AC_CONFIG_HEADERS([config.h]) 9 | AC_CONFIG_AUX_DIR([config]) 10 | AC_CONFIG_MACRO_DIR([m4]) 11 | 12 | #AM_INIT_AUTOMAKE([gnu check-news]) 13 | AM_INIT_AUTOMAKE([gnu]) 14 | 15 | 16 | AC_LANG([C++]) 17 | 18 | # Checks for programs. 19 | AC_PROG_CC 20 | AC_PROG_CXX 21 | AC_PROG_CPP 22 | AC_PROG_INSTALL 23 | AC_PROG_LN_S 24 | AC_PROG_MAKE_SET 25 | 26 | #AC_DISABLE_STATIC 27 | #AC_PROG_LIBTOOL 28 | #AC_SUBST(LIBTOOL_DEPS) 29 | 30 | # Checks for libraries. 31 | 32 | # ---------------------------------------------------------- 33 | # check Qt 34 | AC_ARG_ENABLE(qt4, 35 | AC_HELP_STRING([--enable-qt4], 36 | [use Qt4 tool kit instead of Qt5 (default no)])) 37 | AC_ARG_ENABLE(gl, 38 | AC_HELP_STRING([--enable-gl], 39 | [enable GLWidget for Qt (default yes)])) 40 | 41 | if test "x$enable_qt4" == "xyes"; then 42 | 43 | AC_MSG_NOTICE(enabled Qt4) 44 | 45 | QTMODULES="QtCore QtGui QtNetwork" 46 | 47 | if test "x$enable_gl" == "xyes"; then 48 | AC_MSG_NOTICE(enabled GLWidget) 49 | CFLAGS="-DUSE_GLWIDGET $CFLAGS" 50 | CXXFLAGS="-DUSE_GLWIDGET $CXXFLAGS" 51 | QTMODULES="$QTMODULES QtOpenGL" 52 | fi 53 | 54 | AX_QT([4.3.0],[$QTMODULES]) 55 | else 56 | AC_MSG_NOTICE(enabled Qt5) 57 | 58 | QTMODULES="Qt5Core Qt5Gui Qt5Widgets Qt5Network" 59 | 60 | if test "x$enable_gl" == "xyes"; then 61 | AC_MSG_NOTICE(enabled GL5Widget) 62 | CFLAGS="-DUSE_GLWIDGET $CFLAGS" 63 | CXXFLAGS="-DUSE_GLWIDGET $CXXFLAGS" 64 | QTMODULES="$QTMODULES Qt5OpenGL" 65 | fi 66 | 67 | AX_QT([5.0.0],[$QTMODULES]) 68 | fi 69 | 70 | if test x$have_qt != xyes ; then 71 | AC_MSG_ERROR([$QTMODULES could not be found.]) 72 | AM_CONDITIONAL(BUILD_QT, [test "1" = "0"]) 73 | else 74 | CFLAGS="-fPIC $CFLAGS" 75 | CXXFLAGS="-fPIC $CXXFLAGS" 76 | AM_CONDITIONAL(BUILD_QT, [test "1" = "1"]) 77 | fi 78 | 79 | # ---------------------------------------------------------- 80 | # check C++ 81 | 82 | AX_CXX_COMPILE_STDCXX_17(noext) 83 | 84 | # ---------------------------------------------------------- 85 | # check boost 86 | AX_BOOST_BASE([1.38.0]) 87 | AX_BOOST_SYSTEM 88 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 89 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 90 | LIBS="$LIBS $BOOST_SYSTEM_LIB" 91 | 92 | # check librcsc path 93 | AC_SUBST(LIBRCSCLIB) 94 | LIBRCSCLIB="/usr/local/lib" 95 | librcsc_prefix="" 96 | AC_ARG_WITH(librcsc, 97 | [ --with-librcsc=PREFIX prefix where librcsc is installed (optional)], 98 | librcsc_prefix="$withval", 99 | librcsc_prefix="") 100 | if test x$librcsc_prefix != x; then 101 | CPPFLAGS="$CPPFLAGS -I$librcsc_prefix/include" 102 | LDFLAGS="$LDFLAGS -L$librcsc_prefix/lib" 103 | LIBRCSCLIB="$librcsc_prefix/lib" 104 | else 105 | for librcsc_path_tmp in $HOME/.local $HOME/local $HOME/rcss /opt/robocup /opt /opt/local ; do 106 | if test -d "$librcsc_path_tmp/include/rcsc" && test -r "$librcsc_path_tmp/include/rcsc/types.h" ; then 107 | CPPFLAGS="$CPPFLAGS -I$librcsc_path_tmp/include" 108 | LDFLAGS="$LDFLAGS -L$librcsc_path_tmp/lib" 109 | LIBRCSCLIB="$librcsc_path_tmp/lib" 110 | break; 111 | fi 112 | done 113 | fi 114 | 115 | # Checks for libraries. 116 | AC_CHECK_LIB([m], [cos], 117 | [LIBS="-lm $LIBS"], 118 | [AC_MSG_ERROR([*** -lm not found! ***])]) 119 | AC_CHECK_LIB([rcsc], [main], 120 | [LIBS="-lrcsc $LIBS"], 121 | [AC_MSG_ERROR([*** -lrcsc not found! ***])]) 122 | 123 | # Checks for header files. 124 | 125 | # Checks for typedefs, structures, and compiler characteristics. 126 | AC_HEADER_STDBOOL 127 | AC_C_CONST 128 | AC_C_INLINE 129 | AC_TYPE_SIZE_T 130 | AC_TYPE_UINT32_T 131 | AC_CHECK_TYPES([ptrdiff_t]) 132 | 133 | # Checks for library functions. 134 | AC_HEADER_STDC 135 | AC_CHECK_FUNCS([sqrt rint]) 136 | 137 | AC_CONFIG_FILES([Makefile 138 | src/Makefile 139 | tool/Makefile 140 | tool/dttrainer/Makefile]) 141 | 142 | AC_OUTPUT 143 | -------------------------------------------------------------------------------- /tool/average_formation.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace rcsc; 10 | 11 | class AverageConfGenerator { 12 | private: 13 | Formation::Ptr M_base_formation; 14 | Formation::Ptr M_target_formation; 15 | public: 16 | 17 | private: 18 | bool openBaseFormation( const std::string & filepath ); 19 | bool openTargetFormation( const std::string & filepath ); 20 | 21 | public: 22 | 23 | bool generate( const std::string & base_filepath, 24 | const std::string & target_filepath ); 25 | }; 26 | 27 | /*-------------------------------------------------------------------*/ 28 | /*! 29 | 30 | */ 31 | bool 32 | AverageConfGenerator::openBaseFormation( const std::string & filepath ) 33 | { 34 | M_base_formation = FormationParser::parse( filepath ); 35 | 36 | if ( ! M_base_formation ) 37 | { 38 | std::cerr << "Could not open the base formation [" 39 | << filepath << "]" << std::endl; 40 | return false; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | /*-------------------------------------------------------------------*/ 47 | /*! 48 | 49 | */ 50 | bool 51 | AverageConfGenerator::openTargetFormation( const std::string & filepath ) 52 | { 53 | M_target_formation = FormationParser::parse( filepath ); 54 | 55 | if ( ! M_target_formation ) 56 | { 57 | std::cerr << "Could not open the target formation [" 58 | << filepath << "]" << std::endl; 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | 65 | /*-------------------------------------------------------------------*/ 66 | /*! 67 | 68 | */ 69 | bool 70 | AverageConfGenerator::generate( const std::string & base_filepath, 71 | const std::string & target_filepath ) 72 | { 73 | if ( ! openBaseFormation( base_filepath ) 74 | || ! openTargetFormation( target_filepath ) ) 75 | { 76 | return false; 77 | } 78 | 79 | FormationData::ConstPtr base_data = M_base_formation->toData(); 80 | if ( ! base_data ) 81 | { 82 | std::cerr << "Could not get the sample data of base formation." 83 | << std::endl; 84 | return false; 85 | } 86 | 87 | Formation::Ptr average_formation( new FormationDT() ); 88 | 89 | // 90 | // set role info 91 | // 92 | for ( int num = 1; num <= 11; ++num ) 93 | { 94 | std::string role_name = M_base_formation->roleName( num ); 95 | RoleType role_type = M_base_formation->roleType( num ); 96 | int paired_num = M_base_formation->pairedNumber( num ); 97 | 98 | average_formation->setRole( num, role_name, role_type, paired_num ); 99 | } 100 | 101 | // 102 | // create new data set 103 | // 104 | 105 | FormationData average_data; 106 | 107 | for ( const FormationData::Data & base : base_data->dataCont() ) 108 | { 109 | FormationData::Data new_data; 110 | new_data.ball_ = base.ball_; 111 | 112 | M_target_formation->getPositions( base.ball_, new_data.players_ ); 113 | 114 | for ( int num = 1; num <= 11; ++num ) 115 | { 116 | new_data.players_[num-1] += base.players_[num-1]; 117 | new_data.players_[num-1] *= 0.5; 118 | } 119 | 120 | average_data.addData( new_data ); 121 | } 122 | 123 | 124 | // 125 | // train formation model 126 | // 127 | if ( ! average_formation->train( average_data ) ) 128 | { 129 | return false; 130 | } 131 | 132 | // 133 | // print 134 | // 135 | average_formation->print( std::cout ); 136 | 137 | return true; 138 | } 139 | 140 | /*-------------------------------------------------------------------*/ 141 | /*! 142 | 143 | */ 144 | static 145 | void 146 | usage( const char * prog ) 147 | { 148 | std::cerr << prog << " base.conf target.conf" << std::endl; 149 | } 150 | 151 | /*-------------------------------------------------------------------*/ 152 | /*! 153 | 154 | */ 155 | int 156 | main( int argc, char ** argv ) 157 | { 158 | if ( argc < 3 ) 159 | { 160 | usage( argv[0] ); 161 | return 1; 162 | } 163 | 164 | AverageConfGenerator g; 165 | g.generate( argv[1], argv[2] ); 166 | 167 | return 0; 168 | } 169 | -------------------------------------------------------------------------------- /src/command.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file command.cpp 5 | \brief edit command class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "command.h" 45 | 46 | #include 47 | 48 | /*-------------------------------------------------------------------*/ 49 | /*! 50 | 51 | */ 52 | MoveCommand::MoveCommand( const QPointF & old_pos, 53 | const QPointF & new_pos, 54 | QUndoCommand * parent ) 55 | : QUndoCommand( parent ) 56 | , M_old_pos( old_pos ) 57 | , M_new_pos( new_pos ) 58 | { 59 | 60 | } 61 | 62 | 63 | /*-------------------------------------------------------------------*/ 64 | /*! 65 | 66 | */ 67 | MoveCommand::~MoveCommand() 68 | { 69 | std::cerr << "delete MoveCommand" 70 | <<"\n old_pos=(" << M_old_pos.x() << ", " << M_old_pos.y() << ")" 71 | <<"\n new_pos=(" << M_new_pos.x() << ", " << M_new_pos.y() << ")" 72 | << std::endl; 73 | } 74 | 75 | /*-------------------------------------------------------------------*/ 76 | /*! 77 | 78 | */ 79 | void 80 | MoveCommand::undo() 81 | { 82 | // M_item->setPos( M_old_pos ); 83 | // M_scene->updateItemPositions(); 84 | std::cerr << "undo " 85 | << " new=" << M_new_pos.x() << ',' << M_new_pos.y() 86 | << " -> old=" << M_old_pos.x() << ',' << M_old_pos.y() 87 | << std::endl; 88 | 89 | updateText(); 90 | } 91 | 92 | /*-------------------------------------------------------------------*/ 93 | /*! 94 | 95 | */ 96 | void 97 | MoveCommand::redo() 98 | { 99 | // M_item->setPos( M_new_pos ); 100 | // M_scene->updateItemPositions(); 101 | std::cerr << "redo " 102 | << " new=" << M_new_pos.x() << ',' << M_new_pos.y() 103 | << " -> old=" << M_old_pos.x() << ',' << M_old_pos.y() 104 | << std::endl; 105 | 106 | updateText(); 107 | } 108 | 109 | /*-------------------------------------------------------------------*/ 110 | /*! 111 | 112 | */ 113 | // bool 114 | // MoveCommand::mergeWith( const QUndoCommand * command ) 115 | // { 116 | // const MoveCommand * merged_command = reinterpret_cast< const MoveCommand * >( command ); 117 | 118 | // if ( M_item != merged_command->M_item ) 119 | // { 120 | // return false; 121 | // } 122 | 123 | // M_new_pos = M_item->pos(); 124 | // updateText(); 125 | // return true; 126 | // } 127 | 128 | /*-------------------------------------------------------------------*/ 129 | /*! 130 | 131 | */ 132 | void 133 | MoveCommand::updateText() 134 | { 135 | // if ( qgraphicsitem_cast< BallItem * >( M_item ) ) 136 | // { 137 | // this->setText( QObject::tr( "Move Ball (%1, %2)" ) 138 | // .arg( M_new_pos.x() ) 139 | // .arg( M_new_pos.y() ) ); 140 | // } 141 | // else if ( PlayerItem * p = qgraphicsitem_cast< PlayerItem * >( M_item ) ) 142 | // { 143 | // this->setText( QObject::tr( "Move Player %1 (%2, %3)" ) 144 | // .arg( p->unum() ) 145 | // .arg( M_new_pos.x() ) 146 | // .arg( M_new_pos.y() ) ); 147 | // } 148 | // else 149 | { 150 | this->setText( QObject::tr( "Move ??? (%1, %2)" ) 151 | .arg( M_new_pos.x() ) 152 | .arg( M_new_pos.y() ) ); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/edit_canvas.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file edit_canvas.h 5 | \brief main edit canvas class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 3, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_EDIT_CANVAS_H 33 | #define FEDIT2_EDIT_CANVAS_H 34 | 35 | #ifdef USE_GLWIDGET 36 | #include 37 | #else 38 | #include 39 | #endif 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include "mouse_state.h" 48 | 49 | #include 50 | 51 | class QPainter; 52 | 53 | class EditData; 54 | class MainWindow; 55 | 56 | /*! 57 | \class EditCanvas 58 | */ 59 | class EditCanvas 60 | : 61 | #ifdef USE_GLWIDGET 62 | public QGLWidget 63 | #else 64 | public QWidget 65 | #endif 66 | { 67 | Q_OBJECT 68 | 69 | private: 70 | 71 | std::weak_ptr< EditData > M_edit_data; 72 | 73 | QTransform M_transform; 74 | 75 | // 76 | // graphics context objects 77 | // 78 | QColor M_field_color; 79 | //QBrush M_field_brush; 80 | QBrush M_field_dark_brush; 81 | QPen M_line_pen; 82 | QPen M_triangle_pen; 83 | QPen M_constraint_pen; 84 | QFont M_triangle_font; 85 | QPen M_area_pen; 86 | QPen M_ball_pen; 87 | QBrush M_ball_brush; 88 | QPen M_player_pen; 89 | QPen M_select_pen; 90 | QBrush M_player_brush; 91 | QBrush M_paired_brush; 92 | QFont M_player_font; 93 | 94 | QBrush M_background_contained_area_brush; 95 | QPen M_background_triangle_pen; 96 | QPen M_background_player_pen; 97 | QBrush M_background_left_team_brush; 98 | QBrush M_background_right_team_brush; 99 | QBrush M_background_paired_brush; 100 | QPen M_background_font_pen; 101 | 102 | QPen M_shoot_line_pen; 103 | QPen M_free_kick_circle_pen; 104 | 105 | //! 0: left, 1: middle, 2: right 106 | MouseState M_mouse_state[3]; 107 | 108 | // not used 109 | EditCanvas( const EditCanvas & ); 110 | const EditCanvas & operator=( const EditCanvas & ); 111 | 112 | public: 113 | 114 | explicit 115 | EditCanvas( QWidget * parent = 0 ); 116 | ~EditCanvas(); 117 | 118 | 119 | void setData( std::shared_ptr< EditData > ptr ) 120 | { 121 | M_edit_data = ptr; 122 | } 123 | 124 | private: 125 | 126 | void setAntialiasFlag( QPainter & painter, 127 | bool on ); 128 | 129 | void drawField( QPainter & painter ); 130 | void drawContainedArea( QPainter & painter ); 131 | void drawData( QPainter & painter ); 132 | void drawPlayers( QPainter & painter ); 133 | void drawBall( QPainter & painter ); 134 | void drawShootLines( QPainter & painter ); 135 | void drawFreeKickCircle( QPainter & painter ); 136 | void drawGoalieMovableArea( QPainter & painter ); 137 | void drawConstraintSelection( QPainter & painter ); 138 | 139 | void drawBackgroundContainedArea( QPainter & painter ); 140 | void drawBackgroundData( QPainter & painter ); 141 | void drawBackgroundPlayers( QPainter & painter ); 142 | 143 | void setFocusPoint( const QPoint & pos ); 144 | 145 | protected: 146 | 147 | void paintEvent( QPaintEvent * ); 148 | 149 | void mouseDoubleClickEvent( QMouseEvent * event ); 150 | void mousePressEvent( QMouseEvent * event ); 151 | void mouseReleaseEvent( QMouseEvent * event ); 152 | void mouseMoveEvent( QMouseEvent * event ); 153 | 154 | public slots: 155 | 156 | //void setScale( double scale ); 157 | void zoomIn(); 158 | void zoomOut(); 159 | void fitToScreen(); 160 | 161 | signals: 162 | void objectMoved(); 163 | void mouseMoved( const QPointF & pos ); 164 | void constraintSelected( int first_index, int second_index ); 165 | 166 | }; 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /m4/ax_boost_system.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_boost_system.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_BOOST_SYSTEM 8 | # 9 | # DESCRIPTION 10 | # 11 | # Test for System library from the Boost C++ libraries. The macro requires 12 | # a preceding call to AX_BOOST_BASE. Further documentation is available at 13 | # . 14 | # 15 | # This macro calls: 16 | # 17 | # AC_SUBST(BOOST_SYSTEM_LIB) 18 | # 19 | # And sets: 20 | # 21 | # HAVE_BOOST_SYSTEM 22 | # 23 | # LICENSE 24 | # 25 | # Copyright (c) 2008 Thomas Porschberg 26 | # Copyright (c) 2008 Michael Tindal 27 | # Copyright (c) 2008 Daniel Casimiro 28 | # 29 | # Copying and distribution of this file, with or without modification, are 30 | # permitted in any medium without royalty provided the copyright notice 31 | # and this notice are preserved. This file is offered as-is, without any 32 | # warranty. 33 | 34 | #serial 20 35 | 36 | AC_DEFUN([AX_BOOST_SYSTEM], 37 | [ 38 | AC_ARG_WITH([boost-system], 39 | AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@], 40 | [use the System library from boost - it is possible to specify a certain library for the linker 41 | e.g. --with-boost-system=boost_system-gcc-mt ]), 42 | [ 43 | if test "$withval" = "no"; then 44 | want_boost="no" 45 | elif test "$withval" = "yes"; then 46 | want_boost="yes" 47 | ax_boost_user_system_lib="" 48 | else 49 | want_boost="yes" 50 | ax_boost_user_system_lib="$withval" 51 | fi 52 | ], 53 | [want_boost="yes"] 54 | ) 55 | 56 | if test "x$want_boost" = "xyes"; then 57 | AC_REQUIRE([AC_PROG_CC]) 58 | AC_REQUIRE([AC_CANONICAL_BUILD]) 59 | CPPFLAGS_SAVED="$CPPFLAGS" 60 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 61 | export CPPFLAGS 62 | 63 | LDFLAGS_SAVED="$LDFLAGS" 64 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 65 | export LDFLAGS 66 | 67 | AC_CACHE_CHECK(whether the Boost::System library is available, 68 | ax_cv_boost_system, 69 | [AC_LANG_PUSH([C++]) 70 | CXXFLAGS_SAVE=$CXXFLAGS 71 | CXXFLAGS= 72 | 73 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], 74 | [[boost::system::error_category *a = 0;]])], 75 | ax_cv_boost_system=yes, ax_cv_boost_system=no) 76 | CXXFLAGS=$CXXFLAGS_SAVE 77 | AC_LANG_POP([C++]) 78 | ]) 79 | if test "x$ax_cv_boost_system" = "xyes"; then 80 | AC_SUBST(BOOST_CPPFLAGS) 81 | 82 | AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available]) 83 | BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` 84 | 85 | LDFLAGS_SAVE=$LDFLAGS 86 | if test "x$ax_boost_user_system_lib" = "x"; then 87 | for libextension in `ls -r $BOOSTLIBDIR/libboost_system* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do 88 | ax_lib=${libextension} 89 | AC_CHECK_LIB($ax_lib, exit, 90 | [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], 91 | [link_system="no"]) 92 | done 93 | if test "x$link_system" != "xyes"; then 94 | for libextension in `ls -r $BOOSTLIBDIR/boost_system* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do 95 | ax_lib=${libextension} 96 | AC_CHECK_LIB($ax_lib, exit, 97 | [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], 98 | [link_system="no"]) 99 | done 100 | fi 101 | 102 | else 103 | for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do 104 | AC_CHECK_LIB($ax_lib, exit, 105 | [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], 106 | [link_system="no"]) 107 | done 108 | 109 | fi 110 | if test "x$ax_lib" = "x"; then 111 | AC_MSG_ERROR(Could not find a version of the Boost::System library!) 112 | fi 113 | if test "x$link_system" = "xno"; then 114 | AC_MSG_ERROR(Could not link against $ax_lib !) 115 | fi 116 | fi 117 | 118 | CPPFLAGS="$CPPFLAGS_SAVED" 119 | LDFLAGS="$LDFLAGS_SAVED" 120 | fi 121 | ]) 122 | -------------------------------------------------------------------------------- /src/coordinate_delegate.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file coordinate_delegate.cpp 5 | \brief coordinate value editor delegate class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "coordinate_delegate.h" 45 | 46 | #include 47 | 48 | /*-------------------------------------------------------------------*/ 49 | /*! 50 | 51 | */ 52 | CoordinateDelegate::CoordinateDelegate( const double & minimum, 53 | const double & maximum, 54 | QObject * parent ) 55 | : QItemDelegate( parent ) 56 | , M_minimum( minimum ) 57 | , M_maximum( maximum ) 58 | { 59 | 60 | } 61 | 62 | /*-------------------------------------------------------------------*/ 63 | /*! 64 | 65 | */ 66 | CoordinateDelegate::~CoordinateDelegate() 67 | { 68 | //std::cerr << "delete CoordinateDelegate" << std::endl; 69 | } 70 | 71 | /*-------------------------------------------------------------------*/ 72 | /*! 73 | 74 | */ 75 | QWidget * 76 | CoordinateDelegate::createEditor( QWidget * parent, 77 | const QStyleOptionViewItem & /*option*/, 78 | const QModelIndex & /*index*/ ) const 79 | { 80 | QDoubleSpinBox * editor = new QDoubleSpinBox( parent ); 81 | editor->setRange( M_minimum, M_maximum ); 82 | editor->setDecimals( 2 ); 83 | editor->setSingleStep( 0.01 ); 84 | editor->setAccelerated( true ); 85 | editor->setKeyboardTracking( false ); 86 | 87 | return editor; 88 | } 89 | 90 | /*-------------------------------------------------------------------*/ 91 | /*! 92 | 93 | */ 94 | void 95 | CoordinateDelegate::setEditorData( QWidget * editor, 96 | const QModelIndex & index ) const 97 | { 98 | bool ok = false; 99 | double value = index.model()->data( index, Qt::EditRole ).toDouble( &ok ); 100 | if ( ! ok ) 101 | { 102 | return; 103 | } 104 | 105 | QDoubleSpinBox * spin_box = static_cast< QDoubleSpinBox * >( editor ); 106 | if ( spin_box ) 107 | { 108 | spin_box->setValue( value ); 109 | } 110 | } 111 | 112 | /*-------------------------------------------------------------------*/ 113 | /*! 114 | 115 | */ 116 | void 117 | CoordinateDelegate::setModelData( QWidget * editor, 118 | QAbstractItemModel * /*model*/, 119 | const QModelIndex & index ) const 120 | { 121 | QDoubleSpinBox * spin_box = static_cast< QDoubleSpinBox * >( editor ); 122 | if ( spin_box ) 123 | { 124 | spin_box->interpretText(); 125 | double value = spin_box->value(); 126 | 127 | //std::cerr << "CoordinateDelegate::setModelData" 128 | // << "\n index=" << index.row() << ',' << index.column() 129 | // << "\n value=" << value 130 | // << std::endl; 131 | 132 | double old_value = index.model()->data( index, Qt::EditRole ).toDouble(); 133 | if ( old_value != value ) 134 | { 135 | emit valueChanged( index, value ); 136 | //model->setData( index, QString::number( value, 'f', 2 ), Qt::EditRole ); 137 | } 138 | } 139 | } 140 | 141 | /*-------------------------------------------------------------------*/ 142 | /*! 143 | 144 | */ 145 | void 146 | CoordinateDelegate::updateEditorGeometry( QWidget * editor, 147 | const QStyleOptionViewItem & option, 148 | const QModelIndex & /*index*/ ) const 149 | { 150 | editor->setGeometry( option.rect ); 151 | } 152 | -------------------------------------------------------------------------------- /src/constraint_delegate.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file constraint_delegate.cpp 5 | \brief constraint index editor delegate class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "constraint_delegate.h" 45 | 46 | #include 47 | 48 | /*-------------------------------------------------------------------*/ 49 | /*! 50 | 51 | */ 52 | ConstraintDelegate::ConstraintDelegate( QObject * parent ) 53 | : QItemDelegate( parent ) 54 | , M_minimum( 0 ) 55 | , M_maximum( 0 ) 56 | { 57 | 58 | } 59 | 60 | /*-------------------------------------------------------------------*/ 61 | /*! 62 | 63 | */ 64 | ConstraintDelegate::~ConstraintDelegate() 65 | { 66 | //std::cerr << "delete ConstraintDelegate" << std::endl; 67 | } 68 | 69 | /*-------------------------------------------------------------------*/ 70 | /*! 71 | 72 | */ 73 | void 74 | ConstraintDelegate::setRange( const int minimum, 75 | const int maximum ) 76 | { 77 | M_minimum = minimum; 78 | M_maximum = maximum; 79 | } 80 | 81 | /*-------------------------------------------------------------------*/ 82 | /*! 83 | 84 | */ 85 | QWidget * 86 | ConstraintDelegate::createEditor( QWidget * parent, 87 | const QStyleOptionViewItem & /*option*/, 88 | const QModelIndex & /*index*/ ) const 89 | { 90 | QSpinBox * editor = new QSpinBox( parent ); 91 | editor->setRange( M_minimum, M_maximum ); 92 | editor->setSingleStep( 1 ); 93 | editor->setAccelerated( true ); 94 | editor->setKeyboardTracking( false ); 95 | editor->setAccelerated( true ); 96 | editor->setWrapping( true ); 97 | 98 | return editor; 99 | } 100 | 101 | /*-------------------------------------------------------------------*/ 102 | /*! 103 | 104 | */ 105 | void 106 | ConstraintDelegate::setEditorData( QWidget * editor, 107 | const QModelIndex & index ) const 108 | { 109 | bool ok = false; 110 | int value = index.model()->data( index, Qt::EditRole ).toInt( &ok ); 111 | if ( ! ok ) 112 | { 113 | return; 114 | } 115 | 116 | QSpinBox * spin_box = static_cast< QSpinBox * >( editor ); 117 | if ( spin_box ) 118 | { 119 | spin_box->setValue( value ); 120 | } 121 | } 122 | 123 | /*-------------------------------------------------------------------*/ 124 | /*! 125 | 126 | */ 127 | void 128 | ConstraintDelegate::setModelData( QWidget * editor, 129 | QAbstractItemModel * /*model*/, 130 | const QModelIndex & index ) const 131 | { 132 | QSpinBox * spin_box = static_cast< QSpinBox * >( editor ); 133 | if ( spin_box ) 134 | { 135 | spin_box->interpretText(); 136 | int value = spin_box->value(); 137 | 138 | //std::cerr << "ConstraintDelegate::setModelData" 139 | // << "\n index=" << index.row() << ',' << index.column() 140 | // << "\n value=" << value 141 | // << std::endl; 142 | 143 | int old_value = index.model()->data( index, Qt::EditRole ).toInt(); 144 | if ( old_value != value ) 145 | { 146 | emit valueChanged( index, value ); 147 | } 148 | } 149 | } 150 | 151 | /*-------------------------------------------------------------------*/ 152 | /*! 153 | 154 | */ 155 | void 156 | ConstraintDelegate::updateEditorGeometry( QWidget * editor, 157 | const QStyleOptionViewItem & option, 158 | const QModelIndex & /*index*/ ) const 159 | { 160 | editor->setGeometry( option.rect ); 161 | } 162 | -------------------------------------------------------------------------------- /src/constraint_edit_dialog.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file constraint_edit_dialog.h 5 | \brief Formation editor position edit Dialog class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "constraint_edit_dialog.h" 45 | 46 | #include "edit_canvas.h" 47 | #include "edit_data.h" 48 | 49 | #include 50 | 51 | /*-------------------------------------------------------------------*/ 52 | /*! 53 | 54 | */ 55 | ConstraintEditDialog::ConstraintEditDialog( QWidget * parent, 56 | EditCanvas * canvas, 57 | std::shared_ptr< EditData > data, 58 | const int origin_index, 59 | const int terminal_index ) 60 | : QDialog( parent ) 61 | , M_edit_canvas( canvas ) 62 | , M_edit_data( data ) 63 | { 64 | Q_ASSERT( canvas ); 65 | Q_ASSERT( data ); 66 | 67 | this->setWindowTitle( tr( "Select Constraints" ) ); 68 | 69 | createWidgets(); 70 | 71 | M_origin->setValue( origin_index + 1 ); 72 | M_terminal->setValue( terminal_index + 1 ); 73 | } 74 | 75 | /*-------------------------------------------------------------------*/ 76 | /*! 77 | 78 | */ 79 | ConstraintEditDialog::~ConstraintEditDialog() 80 | { 81 | //std::cerr << "delete ConstraintEditDialog" << std::endl; 82 | } 83 | 84 | /*-------------------------------------------------------------------*/ 85 | /*! 86 | 87 | */ 88 | int 89 | ConstraintEditDialog::originIndex() const 90 | { 91 | return M_origin->value(); 92 | } 93 | 94 | /*-------------------------------------------------------------------*/ 95 | /*! 96 | 97 | */ 98 | int 99 | ConstraintEditDialog::terminalIndex() const 100 | { 101 | return M_terminal->value(); 102 | } 103 | 104 | /*-------------------------------------------------------------------*/ 105 | /*! 106 | 107 | */ 108 | void 109 | ConstraintEditDialog::createWidgets() 110 | { 111 | QVBoxLayout * top_layout = new QVBoxLayout(); 112 | top_layout->setMargin( 2 ); 113 | top_layout->setSpacing( 2 ); 114 | top_layout->setSizeConstraint( QLayout::SetFixedSize ); 115 | 116 | { 117 | QGridLayout * layout = new QGridLayout(); 118 | 119 | // 120 | layout->addWidget( new QLabel( tr( "origin" ) ), 0, 0 ); 121 | // 122 | layout->addWidget( new QLabel( tr( "terminal" ) ), 0, 1 ); 123 | 124 | // 125 | M_origin = new QSpinBox(); 126 | M_origin->setRange( 1, M_edit_data->formationData()->dataCont().size() ); 127 | M_origin->setWrapping( true ); 128 | connect( M_origin, SIGNAL( valueChanged( int ) ), 129 | this, SLOT( changeIndex() ) ); 130 | layout->addWidget( M_origin, 1, 0 ); 131 | // 132 | M_terminal = new QSpinBox(); 133 | M_terminal->setRange( 1, M_edit_data->formationData()->dataCont().size() ); 134 | M_terminal->setWrapping( true ); 135 | connect( M_terminal, SIGNAL( valueChanged( int ) ), 136 | this, SLOT( changeIndex() ) ); 137 | layout->addWidget( M_terminal, 1, 1 ); 138 | 139 | top_layout->addLayout( layout ); 140 | } 141 | 142 | QDialogButtonBox * button_box = new QDialogButtonBox( QDialogButtonBox::Ok 143 | | QDialogButtonBox::Cancel ); 144 | connect( button_box, SIGNAL( accepted() ), this, SLOT( accept() ) ); 145 | connect( button_box, SIGNAL( rejected() ), this, SLOT( reject() ) ); 146 | top_layout->addWidget( button_box ); 147 | 148 | this->setLayout( top_layout ); 149 | } 150 | 151 | /*-------------------------------------------------------------------*/ 152 | /*! 153 | 154 | */ 155 | void 156 | ConstraintEditDialog::changeIndex() 157 | { 158 | M_edit_data->setConstraintIndex( M_origin->value() - 1, 159 | M_terminal->value() - 1 ); 160 | M_edit_canvas->update(); 161 | } 162 | -------------------------------------------------------------------------------- /src/config_dialog.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file config_dialog.cpp 5 | */ 6 | 7 | /* 8 | *Copyright: 9 | 10 | Copyright (C) Hidehisa AKIYAMA 11 | 12 | This code is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 3, or (at your option) 15 | any later version. 16 | 17 | This code is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this code; see the file COPYING. If not, write to 24 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 25 | 26 | *EndCopyright: 27 | */ 28 | 29 | ///////////////////////////////////////////////////////////////////// 30 | 31 | #ifdef HAVE_CONFIG_H 32 | #include 33 | #endif 34 | 35 | #include 36 | 37 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | #include "config_dialog.h" 44 | 45 | #include "options.h" 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | /*-------------------------------------------------------------------*/ 52 | /*! 53 | 54 | */ 55 | ConfigDialog::ConfigDialog( QWidget * parent ) 56 | : QDialog( parent ) 57 | { 58 | this->setWindowTitle( tr( "Config Dialog" ) ); 59 | createWidgets(); 60 | } 61 | 62 | /*-------------------------------------------------------------------*/ 63 | /*! 64 | 65 | */ 66 | ConfigDialog::~ConfigDialog() 67 | { 68 | //std::cerr << "delete ConfigDialog" << std::endl; 69 | } 70 | 71 | /*-------------------------------------------------------------------*/ 72 | /*! 73 | 74 | */ 75 | void 76 | ConfigDialog::createWidgets() 77 | { 78 | QVBoxLayout * layout = new QVBoxLayout(); 79 | layout->setSizeConstraint( QLayout::SetFixedSize ); 80 | layout->setContentsMargins( 4, 4, 4, 4 ); 81 | layout->setSpacing( 4 ); 82 | 83 | layout->addWidget( createViewSizeControls(), 84 | 0, Qt::AlignLeft ); 85 | layout->addWidget( createViewScaleControls(), 86 | 0, Qt::AlignLeft ); 87 | 88 | this->setLayout( layout ); 89 | } 90 | 91 | /*-------------------------------------------------------------------*/ 92 | /*! 93 | 94 | */ 95 | QWidget * 96 | ConfigDialog::createViewSizeControls() 97 | { 98 | QGroupBox * group_box = new QGroupBox( tr( "View Size" ) ); 99 | 100 | QHBoxLayout * layout = new QHBoxLayout(); 101 | layout->setContentsMargins( 1, 1, 1, 1 ); 102 | layout->setSpacing( 0 ); 103 | 104 | layout->addWidget( new QLabel( tr( " Width:" ) ) ); 105 | 106 | M_view_width_text = new QLineEdit( tr( "640" ) ); 107 | M_view_width_text->setValidator( new QIntValidator( 100, 3000, M_view_width_text ) ); 108 | M_view_width_text->setMaximumSize( 48, 24 ); 109 | layout->addWidget( M_view_width_text ); 110 | 111 | layout->addWidget( new QLabel( tr( " Height:" ) ) ); 112 | 113 | M_view_height_text = new QLineEdit( tr( "480" ) ); 114 | M_view_height_text->setValidator( new QIntValidator( 100, 3000, M_view_height_text ) ); 115 | M_view_height_text->setMaximumSize( 48, 24 ); 116 | layout->addWidget( M_view_height_text ); 117 | 118 | layout->addSpacing( 12 ); 119 | 120 | QPushButton * apply_view_size_btn = new QPushButton( tr( "apply" ) ); 121 | apply_view_size_btn->setMaximumSize( 60, this->fontMetrics().height() + 12 ); 122 | connect( apply_view_size_btn, SIGNAL( clicked() ), 123 | this, SLOT( applyViewSize() ) ); 124 | layout->addWidget( apply_view_size_btn ); 125 | 126 | group_box->setLayout( layout ); 127 | return group_box; 128 | } 129 | 130 | 131 | /*-------------------------------------------------------------------*/ 132 | /*! 133 | 134 | */ 135 | QWidget * 136 | ConfigDialog::createViewScaleControls() 137 | { 138 | QGroupBox * group_box = new QGroupBox( tr( "View Scale" ) ); 139 | 140 | QHBoxLayout * layout = new QHBoxLayout(); 141 | layout->setContentsMargins( 1, 1, 1, 1 ); 142 | layout->setSpacing( 0 ); 143 | 144 | layout->addWidget( new QLabel( tr( " Scale:" ) ) ); 145 | 146 | M_scale_text = new QLineEdit( tr( "0.0" ) ); 147 | M_scale_text->setValidator( new QDoubleValidator( 0.0, 400.0, 3, M_scale_text ) ); 148 | M_scale_text->setMaximumSize( 48, 24 ); 149 | connect( M_scale_text, SIGNAL( textChanged( const QString & ) ), 150 | this, SLOT( editViewScale( const QString & ) ) ); 151 | layout->addWidget( M_scale_text ); 152 | 153 | group_box->setLayout( layout ); 154 | return group_box; 155 | } 156 | 157 | /*-------------------------------------------------------------------*/ 158 | /*! 159 | 160 | */ 161 | void 162 | ConfigDialog::showEvent( QShowEvent * event ) 163 | { 164 | updateAll(); 165 | event->accept(); 166 | emit shown( true ); 167 | } 168 | 169 | /*-------------------------------------------------------------------*/ 170 | /*! 171 | 172 | */ 173 | void 174 | ConfigDialog::closeEvent( QCloseEvent * event ) 175 | { 176 | event->accept(); 177 | emit shown( false ); 178 | } 179 | 180 | /*-------------------------------------------------------------------*/ 181 | /*! 182 | 183 | */ 184 | void 185 | ConfigDialog::updateAll() 186 | { 187 | const Options & opt = Options::instance(); 188 | 189 | M_view_width_text->setText( QString::number( opt.viewWidth() ) ); 190 | M_view_height_text->setText( QString::number( opt.viewHeight() ) ); 191 | } 192 | 193 | /*-------------------------------------------------------------------*/ 194 | /*! 195 | 196 | */ 197 | void 198 | ConfigDialog::applyViewSize() 199 | { 200 | bool ok_w = true; 201 | bool ok_h = true; 202 | int width = M_view_width_text->text().toInt( &ok_w ); 203 | int height = M_view_height_text->text().toInt( &ok_h ); 204 | 205 | if ( ok_w 206 | && ok_h 207 | && width > 0 208 | && height > 0 ) 209 | { 210 | emit viewResizeApplied( QSize( width, height ) ); 211 | } 212 | } 213 | 214 | /*-------------------------------------------------------------------*/ 215 | /*! 216 | 217 | */ 218 | void 219 | ConfigDialog::editViewScale( const QString & text ) 220 | { 221 | bool ok = true; 222 | double value = text.toDouble( &ok ); 223 | 224 | if ( ok 225 | && std::fabs( value - Options::instance().viewScale() ) >= 0.01 ) 226 | { 227 | Options::instance().setAutoFitMode( false ); 228 | Options::instance().setViewScale( value ); 229 | 230 | emit configured(); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /tool/dttrainer/trainer.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file trainer.cpp 5 | \brief trainer for FormationDT Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include "trainer.h" 37 | 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | using namespace rcsc; 46 | 47 | /*-------------------------------------------------------------------*/ 48 | /*! 49 | 50 | */ 51 | Trainer::Trainer() 52 | : M_alpha( 0.1 ), 53 | M_error_thr( 0.1 ), 54 | M_max_loop( 500 ) 55 | { 56 | 57 | } 58 | 59 | /*-------------------------------------------------------------------*/ 60 | /*! 61 | 62 | */ 63 | bool 64 | Trainer::readFormation( const std::string & filepath ) 65 | { 66 | std::ifstream fin( filepath.c_str() ); 67 | 68 | if ( ! fin ) 69 | { 70 | return false; 71 | } 72 | 73 | if ( ! M_formation.read( fin ) ) 74 | { 75 | std::cerr << "Failed to read formation data" << std::endl; 76 | return false; 77 | } 78 | 79 | M_target_data = M_formation.sampleVector(); 80 | 81 | fin.close(); 82 | 83 | return true; 84 | } 85 | 86 | /*-------------------------------------------------------------------*/ 87 | /*! 88 | 89 | */ 90 | bool 91 | Trainer::readTrainingData( const std::string & filepath ) 92 | { 93 | // format: 94 | // 95 | // (b ) ( ) 96 | // 97 | 98 | std::ifstream fin( filepath.c_str() ); 99 | 100 | if ( ! fin ) 101 | { 102 | return false; 103 | } 104 | 105 | std::string line; 106 | int n_line = 0; 107 | while ( std::getline( fin, line ) ) 108 | { 109 | ++n_line; 110 | 111 | int unum; 112 | double bx, by, px, py; 113 | if ( std::sscanf( line.c_str(), 114 | " ( b %lf %lf ) ( %d %lf %lf )", 115 | &bx, &by, &unum, &px, &py ) != 5 ) 116 | { 117 | std::cerr << "line " << n_line 118 | << " illegal data [" << line << "]" << std::endl; 119 | return false; 120 | } 121 | 122 | if ( unum < 0 || 11 < unum ) 123 | { 124 | std::cerr << "line " << n_line 125 | << " illegal unum [" << line << "]" << std::endl; 126 | return false; 127 | } 128 | 129 | M_training_data.push_back( Data( bx, by, unum, px, py ) ); 130 | } 131 | 132 | return true; 133 | } 134 | 135 | 136 | /*-------------------------------------------------------------------*/ 137 | /*! 138 | 139 | */ 140 | std::ostream & 141 | Trainer::printFormation( std::ostream & os ) const 142 | { 143 | M_formation.print( os ); 144 | return os; 145 | } 146 | 147 | /*-------------------------------------------------------------------*/ 148 | /*! 149 | 150 | */ 151 | void 152 | Trainer::train() 153 | { 154 | for ( int i = 0; i < M_max_loop; ++i ) 155 | { 156 | double max_error = 0.0; 157 | 158 | std::cerr << "loop " << i + 1 << std::endl; 159 | 160 | for ( std::vector< Data >::const_iterator it = M_training_data.begin(), end = M_training_data.end(); 161 | it != end; 162 | ++it ) 163 | { 164 | double error_value = train( *it ); 165 | if ( error_value >= 0.0 166 | && error_value > max_error ) 167 | { 168 | max_error = error_value; 169 | } 170 | } 171 | 172 | M_formation.train(); 173 | 174 | if ( max_error < M_error_thr ) 175 | { 176 | break; 177 | } 178 | } 179 | } 180 | 181 | /*-------------------------------------------------------------------*/ 182 | /*! 183 | 184 | */ 185 | double 186 | Trainer::train( const Data & data ) 187 | { 188 | const DelaunayTriangulation::Triangle * t = M_formation.triangulation().findTriangleContains( data.ball_ ); 189 | 190 | if ( ! t ) 191 | { 192 | std::cerr << "Could not find the triangle that contains " << data.ball_ << std::endl; 193 | return -1.0; 194 | } 195 | 196 | const Vector2D old_pos = M_formation.getPosition( data.unum_, data.ball_ ); 197 | 198 | if ( ! old_pos.isValid() ) 199 | { 200 | std::cerr << "Could not calculate the position." 201 | << " ball=" << data.ball_ << " unum=" << data.unum_ << std::endl; 202 | return -1.0; 203 | } 204 | 205 | size_t idx0 = size_t( t->vertex( 0 )->id() ); 206 | size_t idx1 = size_t( t->vertex( 1 )->id() ); 207 | size_t idx2 = size_t( t->vertex( 2 )->id() ); 208 | 209 | if ( idx0 >= M_target_data.size() 210 | || idx1 >= M_target_data.size() 211 | || idx2 >= M_target_data.size() ) 212 | { 213 | std::cerr << "Could not find the target vertex ball=" << data.ball_ << std::endl; 214 | return -1.0; 215 | } 216 | Vector2D diff = data.pos_ - old_pos; 217 | double error_value = diff.r(); 218 | 219 | #if 1 220 | std::cerr << "train:\n" 221 | << " ball=" << data.ball_ << " unum=" << data.unum_ << data.pos_ << '\n'; 222 | std::cerr << " target vertices: " << idx0 << ' ' << idx1 << ' ' << idx2 << '\n'; 223 | std::cerr << " diff=" << diff << " error=" << error_value << std::endl; 224 | #endif 225 | 226 | diff *= M_alpha; 227 | M_target_data[idx0].players_[data.unum_ - 1] += diff; 228 | M_target_data[idx1].players_[data.unum_ - 1] += diff; 229 | M_target_data[idx2].players_[data.unum_ - 1] += diff; 230 | 231 | formation::SampleDataSet::Ptr ptr = M_formation.samples(); 232 | ptr->replaceData( M_formation, idx0, M_target_data[idx0], true ); 233 | ptr->replaceData( M_formation, idx1, M_target_data[idx1], true ); 234 | ptr->replaceData( M_formation, idx2, M_target_data[idx2], true ); 235 | 236 | return error_value; 237 | } 238 | -------------------------------------------------------------------------------- /src/edit_data.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file edit_data.h 5 | \brief formation editor data class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_EDIT_DATA_H 33 | #define FEDIT2_EDIT_DATA_H 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | 43 | class EditData { 44 | public: 45 | 46 | static const double MAX_X; 47 | static const double MAX_Y; 48 | 49 | enum SelectType { 50 | SELECT_BALL, 51 | SELECT_PLAYER, 52 | SELECT_SAMPLE, 53 | NO_SELECT, 54 | }; 55 | 56 | private: 57 | 58 | QString M_filepath; 59 | bool M_conf_changed; 60 | QString M_saved_datetime; 61 | 62 | rcsc::FormationData::Data M_current_state; //!< current state on the edit canvas. 63 | 64 | rcsc::Formation::Ptr M_formation; 65 | rcsc::FormationData::Ptr M_formation_data; //!< training data 66 | rcsc::Triangulation M_triangulation; 67 | 68 | rcsc::Formation::Ptr M_background_formation; 69 | rcsc::Triangulation M_background_triangulation; 70 | 71 | int M_current_index; 72 | 73 | SelectType M_select_type; 74 | int M_select_index; 75 | 76 | int M_constraint_origin_index; 77 | int M_constraint_terminal_index; 78 | rcsc::Vector2D M_constraint_terminal; 79 | 80 | // not used 81 | EditData( const EditData & ); 82 | EditData & operator=( const EditData & ); 83 | public: 84 | 85 | EditData(); 86 | ~EditData(); 87 | 88 | void createFormation( const QString & type_name ); 89 | private: 90 | 91 | void init(); 92 | void backup( const QString & filepath ); 93 | 94 | public: 95 | 96 | const 97 | QString & filePath() const 98 | { 99 | return M_filepath; 100 | } 101 | 102 | bool isConfChanged() const 103 | { 104 | return M_conf_changed; 105 | } 106 | 107 | const rcsc::FormationData::Data & currentState() const 108 | { 109 | return M_current_state; 110 | } 111 | 112 | rcsc::Formation::ConstPtr formation() const 113 | { 114 | return M_formation; 115 | } 116 | rcsc::FormationData::Ptr formationData() const 117 | { 118 | return M_formation_data; 119 | } 120 | const 121 | rcsc::Triangulation & triangulation() const 122 | { 123 | return M_triangulation; 124 | } 125 | 126 | rcsc::Formation::ConstPtr backgroundFormation() const 127 | { 128 | return M_background_formation; 129 | } 130 | const 131 | rcsc::Triangulation & backgroundTriangulation() const 132 | { 133 | return M_background_triangulation; 134 | } 135 | 136 | int currentIndex() const 137 | { 138 | return M_current_index; 139 | } 140 | 141 | SelectType selectType() const 142 | { 143 | return M_select_type; 144 | } 145 | size_t selectIndex() const 146 | { 147 | return M_select_index; 148 | } 149 | 150 | size_t constraintOriginIndex() const 151 | { 152 | return M_constraint_origin_index; 153 | } 154 | 155 | size_t constraintTerminalIndex() const 156 | { 157 | return M_constraint_terminal_index; 158 | } 159 | 160 | const 161 | rcsc::Vector2D & constraintTerminal() const 162 | { 163 | return M_constraint_terminal; 164 | } 165 | 166 | bool openConf( const QString & filepath ); 167 | bool saveConf(); 168 | bool saveConfAs( const QString & filepath ); 169 | 170 | bool openData( const QString & filepath ); 171 | bool saveDataAs( const QString & filepath ); 172 | 173 | bool openBackgroundConf( const QString & filepath ); 174 | 175 | private: 176 | void updatePlayerPosition(); 177 | void updateTriangulation(); 178 | 179 | void reverseY( std::vector< rcsc::Vector2D > * players ); 180 | 181 | std::string replaceDataImpl( const int idx, 182 | const rcsc::FormationData::Data & data ); 183 | public: 184 | 185 | void updateRoleData( const int num, 186 | const int paird_unum, 187 | const std::string & role_name ); 188 | void updateRoleType( const int num, 189 | const int type_index, 190 | const int side_index ); 191 | // void updateMarkerData( const int unum, 192 | // const bool marker, 193 | // const bool setplay_marker ); 194 | 195 | void moveBallTo( const double x, 196 | const double y ); 197 | void movePlayerTo( const int num, 198 | const double x, 199 | const double y ); 200 | // void setConstraintTerminal( const double x, 201 | // const double y ); 202 | // void setConstraintIndex( const int origin_idx, 203 | // const int terminal_idx ); 204 | bool moveSelectObjectTo( const double x, 205 | const double y ); 206 | 207 | bool selectObject( const double x, 208 | const double y ); 209 | bool releaseObject(); 210 | 211 | std::string addData(); 212 | std::string insertData( const int idx ); 213 | std::string replaceData( const int idx ); 214 | std::string replaceBall( const int idx, 215 | const double x, 216 | const double y ); 217 | std::string replacePlayer( const int idx, 218 | const int unum, 219 | const double x, 220 | const double y ); 221 | std::string deleteData( const int idx ); 222 | std::string changeDataIndex( const int old_idx, 223 | const int new_idx ); 224 | 225 | // std::string addConstraint( const int origin_idx, 226 | // const int terminal_idx ); 227 | // std::string replaceConstraint( const int idx, 228 | // const int origin_idx, 229 | // const int terminal_idx ); 230 | // std::string deleteConstraint( const int origin_idx, 231 | // const int terminal_idx ); 232 | 233 | 234 | bool setCurrentIndex( const int idx ); 235 | void reverseY(); 236 | void train(); 237 | }; 238 | 239 | #endif 240 | -------------------------------------------------------------------------------- /src/main_window.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file main_window.h 5 | \brief main application window class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT2_MAIN_WINDOW_H 33 | #define FEDIT2_MAIN_WINDOW_H 34 | 35 | #include 36 | 37 | #include 38 | 39 | class QCloseEvent; 40 | class QLabel; 41 | class QModelIndex; 42 | class QSpinBox; 43 | class QSplitter; 44 | class QToolBar; 45 | class QToolBox; 46 | class QUndoStack; 47 | 48 | class ConfigDialog; 49 | class EditCanvas; 50 | class EditData; 51 | class EditDialog; 52 | //class ConstraintView; 53 | class SampleView; 54 | 55 | /*! 56 | \class MainWindow 57 | */ 58 | class MainWindow 59 | : public QMainWindow { 60 | 61 | Q_OBJECT 62 | 63 | private: 64 | 65 | std::shared_ptr< EditData > M_edit_data; 66 | 67 | QToolBar * M_tool_bar; 68 | QSpinBox * M_index_spin_box; 69 | 70 | QSplitter * M_splitter; 71 | SampleView * M_sample_view; 72 | //ConstraintView * M_constraint_view; 73 | EditCanvas * M_edit_canvas; 74 | EditDialog * M_edit_dialog; 75 | ConfigDialog * M_config_dialog; 76 | 77 | QLabel * M_position_label; 78 | 79 | // file actions 80 | QAction * M_new_file_act; 81 | QAction * M_open_conf_act; 82 | QAction * M_open_background_conf_act; 83 | QAction * M_open_data_act; 84 | QAction * M_save_act; 85 | QAction * M_save_as_act; 86 | QAction * M_save_data_as_act; 87 | QAction * M_quit_act; 88 | 89 | // edit actions 90 | QAction * M_undo_act; 91 | QAction * M_redo_act; 92 | 93 | QAction * M_add_data_act; 94 | QAction * M_insert_data_act; 95 | QAction * M_replace_data_act; 96 | QAction * M_delete_data_act; 97 | QAction * M_reverse_y_act; 98 | //QAction * M_add_constraint_act; 99 | QAction * M_train_act; 100 | 101 | QAction * M_toggle_player_auto_move_act; 102 | QAction * M_toggle_data_auto_select_act; 103 | QAction * M_toggle_pair_mode_act; 104 | //QAction * M_toggle_constraint_edit_mode_act; 105 | 106 | // view actions 107 | QAction * M_full_screen_act; 108 | QAction * M_toggle_tool_bar_act; 109 | QAction * M_toggle_status_bar_act; 110 | QAction * M_zoom_in_act; 111 | QAction * M_zoom_out_act; 112 | QAction * M_fit_to_screen_act; 113 | 114 | QAction * M_toggle_enlarge_act; 115 | QAction * M_toggle_show_index_act; 116 | QAction * M_toggle_show_free_kick_circle_act; 117 | QAction * M_toggle_show_triangulation_act; 118 | QAction * M_toggle_show_circumcircle_act; 119 | QAction * M_toggle_show_shoot_lines_act; 120 | QAction * M_toggle_show_goalie_movable_area_act; 121 | 122 | QAction * M_toggle_antialiasing_act; 123 | QAction * M_toggle_show_background_data_act; 124 | QAction * M_show_edit_dialog_act; 125 | 126 | QAction * M_show_config_dialog_act; 127 | 128 | // help actions 129 | QAction * M_about_act; 130 | 131 | // 132 | // undo 133 | // 134 | 135 | QUndoStack * M_undo_stack; 136 | 137 | 138 | // not used 139 | MainWindow( const MainWindow & ); 140 | const MainWindow & operator=( const MainWindow & ); 141 | 142 | public: 143 | 144 | MainWindow(); 145 | ~MainWindow(); 146 | 147 | void init(); 148 | 149 | private: 150 | 151 | void readSettings(); 152 | void writeSettings(); 153 | 154 | QToolBox * createToolBox(); 155 | void createEditCanvas(); 156 | void createEditDialog(); 157 | void createSampleView(); 158 | //void createConstraintView(); 159 | 160 | void createUndoStack(); 161 | 162 | void createToolBars(); 163 | void createStatusBar(); 164 | 165 | void createActions(); 166 | void createActionsFile(); 167 | void createActionsEdit(); 168 | void createActionsView(); 169 | void createActionsHelp(); 170 | 171 | void createMenus(); 172 | void createMenuFile(); 173 | void createMenuEdit(); 174 | void createMenuView(); 175 | void createMenuHelp(); 176 | 177 | protected: 178 | 179 | void closeEvent( QCloseEvent * event ); 180 | void wheelEvent( QWheelEvent * event ); 181 | 182 | private: 183 | 184 | bool saveChanges(); 185 | 186 | bool openConfFile( const QString & filepath ); 187 | bool openBackgroundConfFile( const QString & filepath ); 188 | bool openDataFile( const QString & filepath ); 189 | 190 | void showWarningMessage( const std::string & err ); 191 | 192 | void updateEditModel(); 193 | 194 | private slots: 195 | 196 | // file 197 | void newFile(); 198 | 199 | void openConf(); 200 | void openBackgroundConf(); 201 | void saveConf(); 202 | void saveConfAs(); 203 | 204 | void openData(); 205 | void saveDataAs(); 206 | 207 | // edit 208 | void setPlayerAutoMove( bool on ); 209 | void setDataAutoSelect( bool on ); 210 | void setPairMode( bool on ); 211 | //void setConstraintEditMode( bool on ); 212 | 213 | void addData(); 214 | void insertData(); 215 | void replaceData(); 216 | void deleteData(); 217 | void changeSampleIndex( int old_visual_index, 218 | int new_visual_index ); 219 | void reverseY(); 220 | void train(); 221 | 222 | // view 223 | void resizeView( const QSize & size ); 224 | void toggleFullScreen(); 225 | void toggleToolBar(); 226 | void toggleStatusBar(); 227 | void setEnlargeMode( bool on ); 228 | void setShowIndex( bool on ); 229 | void setShowFreeKickCircle( bool on ); 230 | void setShowTriangulation( bool on ); 231 | void setShowCircumcircle( bool on ); 232 | void setShowShootLines( bool on ); 233 | void setShowGoalieMovableArea( bool on ); 234 | void setAntialiasing( bool on ); 235 | void toggleShowBackgroundData( bool on ); 236 | 237 | // help 238 | void about(); 239 | 240 | // other 241 | void setPositionLabel( const QPointF & pos ); 242 | void editMenuAboutToShow(); 243 | 244 | void selectSample( int index ); 245 | void selectSampleVisualIndex( int value ); 246 | void deleteSample( int index ); 247 | void replaceBall( int index, 248 | double x, 249 | double y ); 250 | void replacePlayer( int index, 251 | int unum, 252 | double x, 253 | double y ); 254 | 255 | // void deleteConstraint( int origin_idx, 256 | // int terminal_idx ); 257 | // void replaceConstraint( int idx, 258 | // int origin_idx, 259 | // int terminal_idx ); 260 | 261 | void updateDataIndex(); 262 | 263 | // void showConstraintEditDialog(); 264 | // void showConstraintEditDialog( int first_index, 265 | // int second_index ); 266 | signals: 267 | void viewUpdated(); 268 | 269 | }; 270 | 271 | #endif 272 | -------------------------------------------------------------------------------- /src/options.h: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file options.h 5 | \brief global configuration class Header File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef FEDIT_OPTIONS_H 33 | #define FEDIT_OPTIONS_H 34 | 35 | #include 36 | #include 37 | 38 | /*! 39 | \class Options 40 | \brief global configuration holder. 41 | */ 42 | class Options { 43 | public: 44 | 45 | static const int DEFAULT_CANVAS_WIDTH; 46 | static const int DEFAULT_CANVAS_HEIGHT; 47 | 48 | enum { 49 | FIRLD_GOAL_Z = 0, 50 | FIRLD_LINE_Z = 1, 51 | TRIANGULATION_Z = 10, 52 | PLAYER_Z = 20, 53 | BACKGROUND_PLAYER_Z = 25, 54 | BALL_Z = 30, 55 | }; 56 | 57 | private: 58 | 59 | // 60 | // window options 61 | // 62 | bool M_maximize; 63 | bool M_full_screen; 64 | 65 | int M_window_width; 66 | int M_window_height; 67 | int M_window_pos_x; 68 | int M_window_pos_y; 69 | 70 | int M_view_width; 71 | int M_view_height; 72 | 73 | QPointF M_focus_point; 74 | double M_view_scale; 75 | 76 | // 77 | // editor options 78 | // 79 | 80 | QString M_conf_file; 81 | QString M_data_file; 82 | QString M_background_conf_file; 83 | 84 | bool M_auto_backup; 85 | 86 | // 87 | // mode options 88 | // 89 | bool M_player_auto_move; 90 | bool M_data_auto_select; 91 | bool M_pair_mode; 92 | bool M_constraint_edit_mode; 93 | 94 | // 95 | // view options 96 | // 97 | 98 | bool M_show_background_data; 99 | bool M_enlarge; 100 | 101 | bool M_show_index; 102 | bool M_show_triangulation; 103 | bool M_show_circumcircle; 104 | bool M_show_shoot_lines; 105 | bool M_show_free_kick_circle; 106 | bool M_show_goalie_movable_area; 107 | 108 | bool M_antialiasing; 109 | bool M_auto_fit_mode; 110 | 111 | // private access for singleton 112 | Options(); 113 | 114 | // not used 115 | Options( const Options & ); 116 | Options & operator=( const Options & ); 117 | 118 | public: 119 | 120 | ~Options(); 121 | 122 | static 123 | Options & instance(); 124 | 125 | // analyze command line options 126 | bool parseCmdLine( int argc, 127 | char ** argv ); 128 | 129 | private: 130 | // read/write settings 131 | void readSettings(); 132 | void writeSettings(); 133 | 134 | void parseWindowGeometry( const std::string & val ); 135 | 136 | public: 137 | 138 | // 139 | // window options 140 | // 141 | 142 | bool maximize() const 143 | { 144 | return M_maximize; 145 | } 146 | 147 | bool fullScreen() const 148 | { 149 | return M_full_screen; 150 | } 151 | 152 | int windowPosX() const 153 | { 154 | return M_window_pos_x; 155 | } 156 | 157 | int windowPosY() const 158 | { 159 | return M_window_pos_y; 160 | } 161 | 162 | int windowWidth() const 163 | { 164 | return M_window_width; 165 | } 166 | 167 | int windowHeight() const 168 | { 169 | return M_window_height; 170 | } 171 | 172 | int viewWidth() const 173 | { 174 | return M_view_width; 175 | } 176 | 177 | int viewHeight() const 178 | { 179 | return M_view_height; 180 | } 181 | 182 | const QPointF & focusPoint() const 183 | { 184 | return M_focus_point; 185 | } 186 | 187 | double viewScale() const 188 | { 189 | return M_view_scale; 190 | } 191 | 192 | void setViewSize( const int width, 193 | const int height ) 194 | { 195 | M_view_width = width; 196 | M_view_height = height; 197 | } 198 | 199 | void setFocusPoint( const QPointF & p ) 200 | { 201 | M_focus_point = p; 202 | } 203 | 204 | void setViewScale( const double scale ) 205 | { 206 | M_view_scale = scale; 207 | } 208 | 209 | // 210 | // editor options 211 | // 212 | 213 | const QString & confFile() const 214 | { 215 | return M_conf_file; 216 | } 217 | 218 | const QString & backgroundConfFile() const 219 | { 220 | return M_background_conf_file; 221 | } 222 | 223 | const QString & dataFile() const 224 | { 225 | return M_data_file; 226 | } 227 | 228 | bool autoBackup() const 229 | { 230 | return M_auto_backup; 231 | } 232 | 233 | // 234 | // mode options 235 | // 236 | 237 | void setPlayerAutoMove( bool on ) 238 | { 239 | M_player_auto_move = on; 240 | } 241 | bool playerAutoMove() const 242 | { 243 | return M_player_auto_move; 244 | } 245 | 246 | void setDataAutoSelect( bool on ) 247 | { 248 | M_data_auto_select = on; 249 | } 250 | bool dataAutoSelect() const 251 | { 252 | return M_data_auto_select; 253 | } 254 | 255 | void setPairMode( bool on ) 256 | { 257 | M_pair_mode = on; 258 | } 259 | bool pairMode() const 260 | { 261 | return M_pair_mode; 262 | } 263 | 264 | void setConstraintEditMode( bool on ) 265 | { 266 | M_constraint_edit_mode = on; 267 | } 268 | bool constraintEditMode() const 269 | { 270 | return M_constraint_edit_mode; 271 | } 272 | 273 | // 274 | // view options 275 | // 276 | 277 | void setShowBackgroundData( const bool on ) 278 | { 279 | M_show_background_data = on; 280 | } 281 | bool showBackgroundData() const 282 | { 283 | return M_show_background_data; 284 | } 285 | 286 | void setEnlarge( const bool on ) 287 | { 288 | M_enlarge = on; 289 | } 290 | bool enlarge() const 291 | { 292 | return M_enlarge; 293 | } 294 | 295 | void setShowIndex( const bool on ) 296 | { 297 | M_show_index = on; 298 | } 299 | bool showIndex() const 300 | { 301 | return M_show_index; 302 | } 303 | 304 | 305 | void setShowTriangulation( const bool on ) 306 | { 307 | M_show_triangulation = on; 308 | } 309 | bool showTriangulation() const 310 | { 311 | return M_show_triangulation; 312 | } 313 | 314 | void setShowCircumcircle( const bool on ) 315 | { 316 | M_show_circumcircle = on; 317 | } 318 | bool showCircumcircle() const 319 | { 320 | return M_show_circumcircle; 321 | } 322 | 323 | void setShowShootLines( const bool on ) { M_show_shoot_lines = on; } 324 | bool showShootLines() const { return M_show_shoot_lines; } 325 | 326 | void setShowFreeKickCircle( const bool on ) { M_show_free_kick_circle = on; } 327 | bool showFreeKickCircle() const { return M_show_free_kick_circle; } 328 | 329 | void setShowGoalieMovableArea( const bool on ) { M_show_goalie_movable_area = on; } 330 | bool showGoalieMovableArea() const { return M_show_goalie_movable_area; } 331 | 332 | // 333 | 334 | void setAntialiasing( const bool on ) 335 | { 336 | M_antialiasing = on; 337 | } 338 | bool antialiasing() const 339 | { 340 | return M_antialiasing; 341 | } 342 | 343 | // 344 | 345 | void setAutoFitMode( const bool on ) 346 | { 347 | M_auto_fit_mode = on; 348 | } 349 | bool autoFitMode() const 350 | { 351 | return M_auto_fit_mode; 352 | } 353 | 354 | }; 355 | 356 | #endif 357 | -------------------------------------------------------------------------------- /src/constraint_view.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file constrant_view.cpp 5 | \brief constraint data view class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "constraint_view.h" 45 | 46 | #include "constraint_delegate.h" 47 | #include "edit_data.h" 48 | 49 | #include 50 | 51 | /*-------------------------------------------------------------------*/ 52 | /*! 53 | 54 | */ 55 | ConstraintView::ConstraintView( QWidget * parent ) 56 | : QTableWidget( parent ) 57 | { 58 | this->setColumnCount( 3 ); 59 | 60 | this->setSelectionBehavior( QAbstractItemView::SelectRows ); 61 | this->setSelectionMode( QAbstractItemView::SingleSelection ); 62 | //this->setEditTriggers( QAbstractItemView::NoEditTriggers ); 63 | this->setEditTriggers( QAbstractItemView::DoubleClicked ); 64 | this->setAlternatingRowColors( true ); 65 | this->setAutoScroll( true ); 66 | 67 | // this->setDragDropMode( QAbstractItemView::DragDrop ); 68 | // this->setDragDropOverwriteMode( false ); 69 | // this->setDropIndicatorShown( true ); 70 | 71 | QStringList header_labels; 72 | header_labels << tr( "Index" ) << tr( "Origin" ) << tr( "Terminal" ); 73 | //header_labels << tr( "Origin" ) << tr( "Terminal" ); 74 | this->setHorizontalHeaderLabels( header_labels ); 75 | 76 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 77 | this->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch ); 78 | #else 79 | //this->horizontalHeader()->setResizeMode( QHeaderView::ResizeToContents ); 80 | this->horizontalHeader()->setResizeMode( QHeaderView::Stretch ); 81 | //this->horizontalHeader()->setStretchLastSection( true ); 82 | #endif 83 | 84 | this->verticalHeader()->hide(); 85 | 86 | connect( this, SIGNAL( currentItemChanged( QTableWidgetItem *, QTableWidgetItem * ) ), 87 | this, SLOT( setCurrentData( QTableWidgetItem * ) ) ); 88 | 89 | M_origin_delegate = new ConstraintDelegate( this ); 90 | M_terminal_delegate = new ConstraintDelegate( this ); 91 | 92 | this->setItemDelegateForColumn( 1, M_origin_delegate ); 93 | this->setItemDelegateForColumn( 2, M_terminal_delegate ); 94 | 95 | connect( M_origin_delegate, SIGNAL( valueChanged( const QModelIndex &, int ) ), 96 | this, SLOT( changeConstraintIndex( const QModelIndex &, int ) ) ); 97 | connect( M_terminal_delegate, SIGNAL( valueChanged( const QModelIndex &, int ) ), 98 | this, SLOT( changeConstraintIndex( const QModelIndex &, int ) ) ); 99 | } 100 | 101 | /*-------------------------------------------------------------------*/ 102 | /*! 103 | 104 | */ 105 | ConstraintView::~ConstraintView() 106 | { 107 | //std::cerr << "delete ConstraintView" << std::endl; 108 | } 109 | 110 | /*-------------------------------------------------------------------*/ 111 | /*! 112 | 113 | */ 114 | void 115 | ConstraintView::updateData() 116 | { 117 | std::shared_ptr< EditData > ptr = M_edit_data.lock(); 118 | if ( ! ptr 119 | || ! ptr->formationData() ) 120 | { 121 | M_origin_delegate->setRange( 0, 0 ); 122 | M_terminal_delegate->setRange( 0, 0 ); 123 | return; 124 | } 125 | 126 | // 127 | // update range 128 | // 129 | 130 | if ( ! ptr->formationData()->constraints().empty() ) 131 | { 132 | int maximum = ptr->formationData()->dataCont().size(); 133 | M_origin_delegate->setRange( 1, maximum ); 134 | M_terminal_delegate->setRange( 1, maximum ); 135 | } 136 | 137 | // 138 | // update constraints 139 | // 140 | 141 | const int data_count = ptr->formationData()->constraints().size(); 142 | 143 | while ( this->rowCount() > data_count ) 144 | { 145 | this->removeRow( this->rowCount() - 1 ); 146 | } 147 | 148 | int idx = 0; 149 | for ( const rcsc::FormationData::Constraint & c : ptr->formationData()->constraints() ) 150 | { 151 | QTableWidgetItem * item = this->item( idx, 0 ); 152 | if ( ! item ) 153 | { 154 | this->insertRow( idx ); 155 | int col = 0; 156 | 157 | item = new QTableWidgetItem( QString::number( idx + 1 ) ); // index 158 | item->setFlags( Qt::ItemIsSelectable 159 | | Qt::ItemIsEnabled 160 | ); 161 | this->setItem( idx, col, item ); 162 | ++col; 163 | 164 | item = new QTableWidgetItem( QString::number( c.first->index_ + 1 ) ); 165 | item->setFlags( Qt::ItemIsSelectable 166 | | Qt::ItemIsEditable 167 | | Qt::ItemIsDragEnabled 168 | //| Qt::ItemIsDropEnabled 169 | | Qt::ItemIsUserCheckable 170 | | Qt::ItemIsEnabled 171 | ); 172 | this->setItem( idx, col, item ); 173 | ++col; 174 | 175 | item = new QTableWidgetItem( QString::number( c.second->index_ + 1 ) ); 176 | item->setFlags( Qt::ItemIsSelectable 177 | | Qt::ItemIsEditable 178 | | Qt::ItemIsDragEnabled 179 | //| Qt::ItemIsDropEnabled 180 | | Qt::ItemIsUserCheckable 181 | | Qt::ItemIsEnabled 182 | ); 183 | this->setItem( idx, col, item ); 184 | ++col; 185 | } 186 | ++idx; 187 | } 188 | } 189 | 190 | /*-------------------------------------------------------------------*/ 191 | /*! 192 | 193 | */ 194 | void 195 | ConstraintView::contextMenuEvent( QContextMenuEvent * event ) 196 | { 197 | QTableWidgetItem * item = this->itemAt( event->pos() ); 198 | 199 | if ( ! item ) 200 | { 201 | return; 202 | } 203 | 204 | if ( ! item->isSelected() ) 205 | { 206 | //this->setCurrentItem( item ); 207 | this->setCurrentCell( this->row( item ), 0 ); 208 | } 209 | 210 | std::cerr << "ConstraintView::contextMenuEvent " 211 | << event->pos().x() << ',' << event->pos().y() 212 | << " row=" << this->currentRow() 213 | << std::endl; 214 | 215 | QMenu menu( this ); 216 | //menu.addAction( tr( "Change Index" ), this, SLOT( menuChangeSampleIndex() ) ); 217 | menu.addAction( tr( "Delete" ), this, SLOT( menuDeleteConstraint() ) ); 218 | 219 | menu.exec( event->globalPos() ); 220 | } 221 | 222 | /*-------------------------------------------------------------------*/ 223 | /*! 224 | 225 | */ 226 | void 227 | ConstraintView::setCurrentData( QTableWidgetItem * current ) 228 | { 229 | int idx = this->row( current ); 230 | std::cerr << "ConstraintView::setCurrentData() index=" << idx 231 | << " currentRow=" << this->currentRow() 232 | << std::endl; 233 | if ( 0 <= idx ) 234 | { 235 | emit constraintSelected( idx ); 236 | } 237 | } 238 | 239 | /*-------------------------------------------------------------------*/ 240 | /*! 241 | 242 | */ 243 | void 244 | ConstraintView::menuDeleteConstraint() 245 | { 246 | int idx = this->currentRow(); 247 | if ( 0 <= idx ) 248 | { 249 | int origin = this->item( idx, 1 )->text().toInt(); 250 | int terminal = this->item( idx, 2 )->text().toInt(); 251 | std::cerr << "ConstraintView::menuDeleteConstraint() index=" << idx 252 | << " origin=" << origin - 1 253 | << " terminal=" << terminal - 1 254 | << std::endl; 255 | emit constraintDeleteRequested( origin - 1, terminal - 1 ); 256 | } 257 | } 258 | 259 | 260 | /*-------------------------------------------------------------------*/ 261 | /*! 262 | 263 | */ 264 | void 265 | ConstraintView::changeConstraintIndex( const QModelIndex & index, 266 | int value ) 267 | { 268 | QTableWidgetItem * origin_item = this->item( index.row(), 1 ); 269 | QTableWidgetItem * terminal_item = this->item( index.row(), 2 ); 270 | 271 | if ( ! origin_item 272 | || ! terminal_item ) 273 | { 274 | return; 275 | } 276 | 277 | int origin = 0; 278 | int terminal = 0; 279 | 280 | if ( index.column() == 1 ) 281 | { 282 | origin = value - 1; 283 | terminal = terminal_item->text().toInt() - 1; 284 | } 285 | else if ( index.column() == 2 ) 286 | { 287 | origin = origin_item->text().toInt() - 1; 288 | terminal = value - 1; 289 | } 290 | else 291 | { 292 | std::cerr << __FILE__ << ':' << __LINE__ << ':' 293 | << " Illegal column count" 294 | << std::endl; 295 | return; 296 | } 297 | 298 | std::cerr << "ConstraintView::changeConstraintIndex " 299 | << " index=" << index.row() << ',' << index.column() 300 | << " (" << origin_item->text().toStdString() 301 | << ',' << terminal_item->text().toStdString() << ")" 302 | << "->(" << origin << ',' << terminal << ')' 303 | << std::endl; 304 | 305 | emit constraintReplaced( index.row(), origin, terminal ); 306 | } 307 | -------------------------------------------------------------------------------- /src/options.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file options.cpp 5 | \brief global configuration class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 3, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | #include 38 | 39 | #include "options.h" 40 | 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | /*-------------------------------------------------------------------*/ 49 | /*! 50 | 51 | */ 52 | Options & 53 | Options::instance() 54 | { 55 | static Options s_instance; 56 | return s_instance; 57 | } 58 | 59 | /*-------------------------------------------------------------------*/ 60 | /*! 61 | 62 | */ 63 | Options::Options() 64 | : M_maximize( false ), 65 | M_full_screen( false ), 66 | M_window_width( 0 ), 67 | M_window_height( 0 ), 68 | M_window_pos_x( -1 ), 69 | M_window_pos_y( -1 ), 70 | M_view_width( 0 ), 71 | M_view_height( 0 ), 72 | M_focus_point( 0.0, 0.0 ), 73 | M_view_scale( 1.0 ), 74 | M_conf_file(), 75 | M_data_file(), 76 | M_background_conf_file(), 77 | M_auto_backup( true ), 78 | // 79 | M_player_auto_move( true ), 80 | M_data_auto_select( true ), 81 | M_pair_mode( true ), 82 | M_constraint_edit_mode( false ), 83 | // 84 | M_show_background_data( true ), 85 | M_enlarge( true ), 86 | M_show_index( true ), 87 | M_show_triangulation( true ), 88 | M_show_circumcircle( false ), 89 | M_show_shoot_lines( false ), 90 | M_show_free_kick_circle( false ), 91 | M_antialiasing( false ), 92 | M_auto_fit_mode( true ) 93 | { 94 | readSettings(); 95 | } 96 | 97 | /*-------------------------------------------------------------------*/ 98 | /*! 99 | 100 | */ 101 | Options::~Options() 102 | { 103 | writeSettings(); 104 | } 105 | 106 | /*-------------------------------------------------------------------*/ 107 | /*! 108 | 109 | */ 110 | void 111 | Options::readSettings() 112 | { 113 | #ifdef Q_WS_WIN 114 | QSettings settings( QDir::currentPath() + QObject::tr( "/fedit2.ini" ), 115 | QSettings::IniFormat ); 116 | #else 117 | QSettings settings( QDir::homePath() + QObject::tr( "/.fedit2" ), 118 | QSettings::IniFormat ); 119 | #endif 120 | 121 | settings.beginGroup( "Global" ); 122 | 123 | 124 | QVariant val; 125 | 126 | // val = settings.value( "maximize" ); 127 | // if ( val.isValid() ) M_maximize = val.toBool(); 128 | 129 | // val = settings.value( "full_screen" ); 130 | // if ( val.isValid() ) M_full_screen = val.toBool(); 131 | 132 | // val = settings.value( "geometry" ); 133 | // if ( val.isValid() ) 134 | // { 135 | // parseWindowGeometry( val.toString().toStdString() ); 136 | // } 137 | 138 | settings.endGroup(); 139 | } 140 | 141 | /*-------------------------------------------------------------------*/ 142 | /*! 143 | 144 | */ 145 | void 146 | Options::writeSettings() 147 | { 148 | #ifdef Q_WS_WIN 149 | QSettings settings( QDir::currentPath() + QObject::tr( "/fedit2.ini" ), 150 | QSettings::IniFormat ); 151 | #else 152 | QSettings settings( QDir::homePath() + QObject::tr( "/.fedit2" ), 153 | QSettings::IniFormat ); 154 | #endif 155 | 156 | settings.beginGroup( "Global" ); 157 | 158 | // settings.setValue( "maximize", M_maximize ); 159 | // settings.setValue( "full_screen", M_full_screen ); 160 | 161 | // if ( M_window_width > 0 162 | // && M_window_height > 0 ) 163 | // { 164 | // settings.setValue( "geometry", 165 | // QString( "%1 x %2 %3 %4" ) 166 | // .arg( M_window_width ) 167 | // .arg( M_window_height ) 168 | // .arg( M_window_pos_x ) 169 | // .arg( M_window_pos_y ) ); 170 | // } 171 | 172 | settings.endGroup(); 173 | } 174 | 175 | /*-------------------------------------------------------------------*/ 176 | /*! 177 | 178 | */ 179 | bool 180 | Options::parseCmdLine( int argc, 181 | char ** argv ) 182 | { 183 | rcsc::ParamMap system_options( "System Options" ); 184 | rcsc::ParamMap window_options( "Window Options" ); 185 | rcsc::ParamMap editor_options( "Editor Options" ); 186 | rcsc::ParamMap view_options( "View Options" ); 187 | 188 | bool help = false; 189 | bool version = false; 190 | 191 | system_options.add() 192 | ( "help", "h", 193 | rcsc::BoolSwitch( &help ), 194 | "print this message." ) 195 | ( "version", "v", 196 | rcsc::BoolSwitch( &version ), 197 | "print version." ) 198 | ; 199 | 200 | std::string geometry; 201 | 202 | window_options.add() 203 | ( "maximize", "", 204 | rcsc::BoolSwitch( &M_maximize ), 205 | "start with a maximized window." ) 206 | ( "full-screen", "", 207 | rcsc::BoolSwitch( &M_full_screen ), 208 | "start with a full screen window." ) 209 | ( "geometry", "", 210 | &geometry, 211 | "specifies the window geometry \"[WxH][+X+Y]\". e.g. --geometry=1024x768+0+0" ) 212 | ; 213 | 214 | std::string conf_file; 215 | std::string data_file; 216 | std::string background_conf_file; 217 | 218 | editor_options.add() 219 | ( "conf", "c", 220 | &conf_file, 221 | "specifies a .conf file." ) 222 | ( "data", "d", 223 | &data_file, 224 | "specifies a .dat file." ) 225 | ( "background-conf", "C", 226 | &background_conf_file, 227 | "specifies a .conf file as a background data." ) 228 | ( "auto-backup", "", 229 | &M_auto_backup, 230 | "make backup files automatically" ) 231 | ; 232 | 233 | view_options.add() 234 | ( "no-antialiasing", "", 235 | rcsc::NegateSwitch( &M_antialiasing ), 236 | "disable antialiasing painting." ) 237 | ( "no-auto-fit", "", 238 | rcsc::NegateSwitch( &M_auto_fit_mode ), 239 | "disable automatic view area fitting." ) 240 | ; 241 | 242 | rcsc::CmdLineParser parser( argc, argv ); 243 | 244 | parser.parse( system_options ); 245 | parser.parse( window_options ); 246 | parser.parse( editor_options ); 247 | parser.parse( view_options ); 248 | 249 | // 250 | // analyze positional options 251 | // 252 | 253 | for ( std::vector< std::string >::const_iterator it = parser.positionalOptions().begin(); 254 | it != parser.positionalOptions().end(); 255 | ++it ) 256 | { 257 | // ".conf" 258 | if ( it->length() > 5 259 | && it->compare( it->length() - 5, 5, ".conf" ) == 0 ) 260 | { 261 | if ( conf_file.empty() ) 262 | { 263 | conf_file = *it; 264 | } 265 | else if ( background_conf_file.empty() ) 266 | { 267 | background_conf_file = *it; 268 | } 269 | else // if ( ! conf_file.empty() && ! background_conf_file.empty() ) 270 | { 271 | help = true; 272 | break; 273 | } 274 | } 275 | else 276 | { 277 | help = true; 278 | break; 279 | } 280 | } 281 | 282 | M_conf_file = QString::fromStdString( conf_file ); 283 | M_data_file = QString::fromStdString( data_file ); 284 | M_background_conf_file = QString::fromStdString( background_conf_file ); 285 | 286 | // 287 | // help message 288 | // 289 | if ( help 290 | || parser.failed() 291 | || parser.positionalOptions().size() > 4 ) 292 | { 293 | std::cout << "Usage: " << "fedit" 294 | << " [options ... ] [conf file [background conf file]] [dat file]" 295 | << std::endl; 296 | system_options.printHelp( std::cout, false ); // with_default = false 297 | window_options.printHelp( std::cout ); 298 | editor_options.printHelp( std::cout ); 299 | view_options.printHelp( std::cout ); 300 | return false; 301 | } 302 | 303 | // 304 | // version message 305 | // 306 | if ( version ) 307 | { 308 | std::cout << "fedit" << " Version " << VERSION 309 | << std::endl; 310 | return false; 311 | } 312 | 313 | // 314 | // window size and position 315 | // 316 | 317 | parseWindowGeometry( geometry ); 318 | 319 | return true; 320 | } 321 | 322 | /*-------------------------------------------------------------------*/ 323 | /*! 324 | 325 | */ 326 | void 327 | Options::parseWindowGeometry( const std::string & val ) 328 | { 329 | if ( val.empty() ) 330 | { 331 | return; 332 | } 333 | 334 | int w = -1, h = -1; 335 | int x = -1, y = -1; 336 | 337 | int num = std::sscanf( val.c_str(), 338 | " %d x %d %d %d " , 339 | &w, &h, &x, &y ); 340 | if ( num == 4 || num == 2 ) 341 | { 342 | if ( w <= 0 || h <= 0 ) 343 | { 344 | std::cerr << "Illegal window size [" << val 345 | << "]" << std::endl; 346 | M_window_width = -1; 347 | M_window_height = -1; 348 | M_window_pos_x = -1; 349 | M_window_pos_y = -1; 350 | } 351 | else 352 | { 353 | M_window_width = w; 354 | M_window_height = h; 355 | M_window_pos_x = x; 356 | M_window_pos_y = y; 357 | } 358 | } 359 | else if ( std::sscanf( val.c_str(), 360 | " %d %d " , 361 | &x, &y ) == 2 ) 362 | { 363 | M_window_pos_x = x; 364 | M_window_pos_y = y; 365 | } 366 | else 367 | { 368 | std::cerr << "Illegal geometry format [" << val 369 | << "]" << std::endl; 370 | } 371 | 372 | } 373 | -------------------------------------------------------------------------------- /m4/ax_boost_base.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_boost_base.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Test for the Boost C++ libraries of a particular version (or newer) 12 | # 13 | # If no path to the installed boost library is given the macro searchs 14 | # under /usr, /usr/local, /opt, /opt/local and /opt/homebrew and evaluates 15 | # the $BOOST_ROOT environment variable. Further documentation is available 16 | # at . 17 | # 18 | # This macro calls: 19 | # 20 | # AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS) 21 | # 22 | # And sets: 23 | # 24 | # HAVE_BOOST 25 | # 26 | # LICENSE 27 | # 28 | # Copyright (c) 2008 Thomas Porschberg 29 | # Copyright (c) 2009 Peter Adolphs 30 | # 31 | # Copying and distribution of this file, with or without modification, are 32 | # permitted in any medium without royalty provided the copyright notice 33 | # and this notice are preserved. This file is offered as-is, without any 34 | # warranty. 35 | 36 | #serial 52 37 | 38 | # example boost program (need to pass version) 39 | m4_define([_AX_BOOST_BASE_PROGRAM], 40 | [AC_LANG_PROGRAM([[ 41 | #include 42 | ]],[[ 43 | (void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))])); 44 | ]])]) 45 | 46 | AC_DEFUN([AX_BOOST_BASE], 47 | [ 48 | AC_ARG_WITH([boost], 49 | [AS_HELP_STRING([--with-boost@<:@=ARG@:>@], 50 | [use Boost library from a standard location (ARG=yes), 51 | from the specified location (ARG=), 52 | or disable it (ARG=no) 53 | @<:@ARG=yes@:>@ ])], 54 | [ 55 | AS_CASE([$withval], 56 | [no],[want_boost="no";_AX_BOOST_BASE_boost_path=""], 57 | [yes],[want_boost="yes";_AX_BOOST_BASE_boost_path=""], 58 | [want_boost="yes";_AX_BOOST_BASE_boost_path="$withval"]) 59 | ], 60 | [want_boost="yes"]) 61 | 62 | 63 | AC_ARG_WITH([boost-libdir], 64 | [AS_HELP_STRING([--with-boost-libdir=LIB_DIR], 65 | [Force given directory for boost libraries. 66 | Note that this will override library path detection, 67 | so use this parameter only if default library detection fails 68 | and you know exactly where your boost libraries are located.])], 69 | [ 70 | AS_IF([test -d "$withval"], 71 | [_AX_BOOST_BASE_boost_lib_path="$withval"], 72 | [AC_MSG_ERROR([--with-boost-libdir expected directory name])]) 73 | ], 74 | [_AX_BOOST_BASE_boost_lib_path=""]) 75 | 76 | BOOST_LDFLAGS="" 77 | BOOST_CPPFLAGS="" 78 | AS_IF([test "x$want_boost" = "xyes"], 79 | [_AX_BOOST_BASE_RUNDETECT([$1],[$2],[$3])]) 80 | AC_SUBST(BOOST_CPPFLAGS) 81 | AC_SUBST(BOOST_LDFLAGS) 82 | ]) 83 | 84 | 85 | # convert a version string in $2 to numeric and affect to polymorphic var $1 86 | AC_DEFUN([_AX_BOOST_BASE_TONUMERICVERSION],[ 87 | AS_IF([test "x$2" = "x"],[_AX_BOOST_BASE_TONUMERICVERSION_req="1.20.0"],[_AX_BOOST_BASE_TONUMERICVERSION_req="$2"]) 88 | _AX_BOOST_BASE_TONUMERICVERSION_req_shorten=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\.[[0-9]]*\)'` 89 | _AX_BOOST_BASE_TONUMERICVERSION_req_major=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\)'` 90 | AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_major" = "x"], 91 | [AC_MSG_ERROR([You should at least specify libboost major version])]) 92 | _AX_BOOST_BASE_TONUMERICVERSION_req_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.\([[0-9]]*\)'` 93 | AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_minor" = "x"], 94 | [_AX_BOOST_BASE_TONUMERICVERSION_req_minor="0"]) 95 | _AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` 96 | AS_IF([test "X$_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor" = "X"], 97 | [_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor="0"]) 98 | _AX_BOOST_BASE_TONUMERICVERSION_RET=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req_major \* 100000 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_minor \* 100 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor` 99 | AS_VAR_SET($1,$_AX_BOOST_BASE_TONUMERICVERSION_RET) 100 | ]) 101 | 102 | dnl Run the detection of boost should be run only if $want_boost 103 | AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[ 104 | _AX_BOOST_BASE_TONUMERICVERSION(WANT_BOOST_VERSION,[$1]) 105 | succeeded=no 106 | 107 | 108 | AC_REQUIRE([AC_CANONICAL_HOST]) 109 | dnl On 64-bit systems check for system libraries in both lib64 and lib. 110 | dnl The former is specified by FHS, but e.g. Debian does not adhere to 111 | dnl this (as it rises problems for generic multi-arch support). 112 | dnl The last entry in the list is chosen by default when no libraries 113 | dnl are found, e.g. when only header-only libraries are installed! 114 | AS_CASE([${host_cpu}], 115 | [x86_64],[libsubdirs="lib64 libx32 lib lib64"], 116 | [mips*64*],[libsubdirs="lib64 lib32 lib lib64"], 117 | [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64|e2k|loongarch64],[libsubdirs="lib64 lib lib64"], 118 | [libsubdirs="lib"] 119 | ) 120 | 121 | dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give 122 | dnl them priority over the other paths since, if libs are found there, they 123 | dnl are almost assuredly the ones desired. 124 | AS_CASE([${host_cpu}], 125 | [i?86],[multiarch_libsubdir="lib/i386-${host_os}"], 126 | [armv7l],[multiarch_libsubdir="lib/arm-${host_os}"], 127 | [multiarch_libsubdir="lib/${host_cpu}-${host_os}"] 128 | ) 129 | 130 | dnl first we check the system location for boost libraries 131 | dnl this location is chosen if boost libraries are installed with the --layout=system option 132 | dnl or if you install boost with RPM 133 | AS_IF([test "x$_AX_BOOST_BASE_boost_path" != "x"],[ 134 | AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"]) 135 | AS_IF([test -d "$_AX_BOOST_BASE_boost_path/include" && test -r "$_AX_BOOST_BASE_boost_path/include"],[ 136 | AC_MSG_RESULT([yes]) 137 | BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include" 138 | for _AX_BOOST_BASE_boost_path_tmp in $multiarch_libsubdir $libsubdirs; do 139 | AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) lib path in "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"]) 140 | AS_IF([test -d "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" && test -r "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" ],[ 141 | AC_MSG_RESULT([yes]) 142 | BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"; 143 | break; 144 | ], 145 | [AC_MSG_RESULT([no])]) 146 | done],[ 147 | AC_MSG_RESULT([no])]) 148 | ],[ 149 | if test X"$cross_compiling" = Xyes; then 150 | search_libsubdirs=$multiarch_libsubdir 151 | else 152 | search_libsubdirs="$multiarch_libsubdir $libsubdirs" 153 | fi 154 | for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local /opt/homebrew ; do 155 | if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then 156 | for libsubdir in $search_libsubdirs ; do 157 | if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 158 | done 159 | BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path_tmp/$libsubdir" 160 | BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path_tmp/include" 161 | break; 162 | fi 163 | done 164 | ]) 165 | 166 | dnl overwrite ld flags if we have required special directory with 167 | dnl --with-boost-libdir parameter 168 | AS_IF([test "x$_AX_BOOST_BASE_boost_lib_path" != "x"], 169 | [BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_lib_path"]) 170 | 171 | AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION)]) 172 | CPPFLAGS_SAVED="$CPPFLAGS" 173 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 174 | export CPPFLAGS 175 | 176 | LDFLAGS_SAVED="$LDFLAGS" 177 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 178 | export LDFLAGS 179 | 180 | AC_REQUIRE([AC_PROG_CXX]) 181 | AC_LANG_PUSH(C++) 182 | AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[ 183 | AC_MSG_RESULT(yes) 184 | succeeded=yes 185 | found_system=yes 186 | ],[ 187 | ]) 188 | AC_LANG_POP([C++]) 189 | 190 | 191 | 192 | dnl if we found no boost with system layout we search for boost libraries 193 | dnl built and installed without the --layout=system option or for a staged(not installed) version 194 | if test "x$succeeded" != "xyes" ; then 195 | CPPFLAGS="$CPPFLAGS_SAVED" 196 | LDFLAGS="$LDFLAGS_SAVED" 197 | BOOST_CPPFLAGS= 198 | if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then 199 | BOOST_LDFLAGS= 200 | fi 201 | _version=0 202 | if test -n "$_AX_BOOST_BASE_boost_path" ; then 203 | if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path"; then 204 | for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do 205 | _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` 206 | V_CHECK=`expr $_version_tmp \> $_version` 207 | if test "x$V_CHECK" = "x1" ; then 208 | _version=$_version_tmp 209 | fi 210 | VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` 211 | BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include/boost-$VERSION_UNDERSCORE" 212 | done 213 | dnl if nothing found search for layout used in Windows distributions 214 | if test -z "$BOOST_CPPFLAGS"; then 215 | if test -d "$_AX_BOOST_BASE_boost_path/boost" && test -r "$_AX_BOOST_BASE_boost_path/boost"; then 216 | BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path" 217 | fi 218 | fi 219 | dnl if we found something and BOOST_LDFLAGS was unset before 220 | dnl (because "$_AX_BOOST_BASE_boost_lib_path" = ""), set it here. 221 | if test -n "$BOOST_CPPFLAGS" && test -z "$BOOST_LDFLAGS"; then 222 | for libsubdir in $libsubdirs ; do 223 | if ls "$_AX_BOOST_BASE_boost_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 224 | done 225 | BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$libsubdir" 226 | fi 227 | fi 228 | else 229 | if test "x$cross_compiling" != "xyes" ; then 230 | for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local /opt/homebrew ; do 231 | if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then 232 | for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do 233 | _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` 234 | V_CHECK=`expr $_version_tmp \> $_version` 235 | if test "x$V_CHECK" = "x1" ; then 236 | _version=$_version_tmp 237 | best_path=$_AX_BOOST_BASE_boost_path 238 | fi 239 | done 240 | fi 241 | done 242 | 243 | VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` 244 | BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" 245 | if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then 246 | for libsubdir in $libsubdirs ; do 247 | if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 248 | done 249 | BOOST_LDFLAGS="-L$best_path/$libsubdir" 250 | fi 251 | fi 252 | 253 | if test -n "$BOOST_ROOT" ; then 254 | for libsubdir in $libsubdirs ; do 255 | if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi 256 | done 257 | if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then 258 | version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` 259 | stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` 260 | stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` 261 | V_CHECK=`expr $stage_version_shorten \>\= $_version` 262 | if test "x$V_CHECK" = "x1" && test -z "$_AX_BOOST_BASE_boost_lib_path" ; then 263 | AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) 264 | BOOST_CPPFLAGS="-I$BOOST_ROOT" 265 | BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir" 266 | fi 267 | fi 268 | fi 269 | fi 270 | 271 | CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" 272 | export CPPFLAGS 273 | LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" 274 | export LDFLAGS 275 | 276 | AC_LANG_PUSH(C++) 277 | AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[ 278 | AC_MSG_RESULT(yes) 279 | succeeded=yes 280 | found_system=yes 281 | ],[ 282 | ]) 283 | AC_LANG_POP([C++]) 284 | fi 285 | 286 | if test "x$succeeded" != "xyes" ; then 287 | if test "x$_version" = "x0" ; then 288 | AC_MSG_NOTICE([[We could not detect the boost libraries (version $1 or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.]]) 289 | else 290 | AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) 291 | fi 292 | # execute ACTION-IF-NOT-FOUND (if present): 293 | ifelse([$3], , :, [$3]) 294 | else 295 | AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) 296 | # execute ACTION-IF-FOUND (if present): 297 | ifelse([$2], , :, [$2]) 298 | fi 299 | 300 | CPPFLAGS="$CPPFLAGS_SAVED" 301 | LDFLAGS="$LDFLAGS_SAVED" 302 | 303 | ]) 304 | -------------------------------------------------------------------------------- /src/sample_view.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file sample_view.cpp 5 | \brief sample data view class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "sample_view.h" 45 | 46 | #include "coordinate_delegate.h" 47 | #include "edit_data.h" 48 | 49 | #include 50 | 51 | /*-------------------------------------------------------------------*/ 52 | /*! 53 | 54 | */ 55 | SampleView::SampleView( QWidget * parent ) 56 | : QTreeWidget( parent ) 57 | { 58 | this->setSelectionBehavior( QAbstractItemView::SelectRows ); 59 | this->setSelectionMode( QAbstractItemView::SingleSelection ); 60 | //this->setEditTriggers( QAbstractItemView::NoEditTriggers ); 61 | this->setEditTriggers( QAbstractItemView::DoubleClicked ); 62 | this->setAlternatingRowColors( true ); 63 | this->setAutoScroll( true ); 64 | this->setExpandsOnDoubleClick( true ); 65 | 66 | //this->setDragDropMode( QAbstractItemView::DragOnly ); 67 | this->setDragDropMode( QAbstractItemView::DragDrop ); 68 | //this->setDragDropMode( QAbstractItemView::InternalMove ); 69 | this->setDragDropOverwriteMode( false ); 70 | this->setDropIndicatorShown( true ); 71 | 72 | QStringList header_labels; 73 | //header_labels << tr( "Index" ) << tr( "Value" ); 74 | header_labels << tr( "Index" ) << tr( "X" ) << tr( "Y" ); 75 | this->setHeaderLabels( header_labels ); 76 | //this->setHeaderHidden( true ); 77 | 78 | this->setColumnWidth( 0, this->fontMetrics().width( tr( "1234567890" ) + 64 ) ); 79 | this->setColumnWidth( 1, this->fontMetrics().width( tr( "-12.3456" ) + 32 ) ); 80 | this->setColumnWidth( 2, this->fontMetrics().width( tr( "-12.3456" ) + 32 ) ); 81 | 82 | // M_constraints = new QTreeWidgetItem( this ); 83 | // M_constraints->setText( 0, tr( "Constraints" ) ); 84 | // M_constraints->setExpanded( true ); 85 | // M_constraints->setFlags( Qt::ItemIsEnabled 86 | // | Qt::ItemIsDropEnabled ); 87 | 88 | // M_samples = new QTreeWidgetItem( this ); 89 | // M_samples->setText( 0, tr( "Samples" ) ); 90 | // M_samples->setExpanded( true ); 91 | // M_samples->setFlags( Qt::ItemIsEnabled 92 | // | Qt::ItemIsDropEnabled ); 93 | 94 | connect( this, SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * ) ), 95 | this, SLOT( setCurrentData( QTreeWidgetItem * ) ) ); 96 | // connect( this, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), 97 | // this, SLOT( doubleClickItem( QTreeWidgetItem *, int ) ) ); 98 | 99 | CoordinateDelegate * x_delegate = new CoordinateDelegate( -52.5 - 2.0, 52.5 + 2.0, this ); 100 | CoordinateDelegate * y_delegate = new CoordinateDelegate( -34.0 - 2.0, 34.0 + 2.0, this ); 101 | 102 | this->setItemDelegateForColumn( 1, x_delegate ); 103 | this->setItemDelegateForColumn( 2, y_delegate ); 104 | 105 | connect( x_delegate, SIGNAL( valueChanged( const QModelIndex &, double ) ), 106 | this, SLOT( changeCoordinates( const QModelIndex &, double ) ) ); 107 | connect( y_delegate, SIGNAL( valueChanged( const QModelIndex &, double ) ), 108 | this, SLOT( changeCoordinates( const QModelIndex &, double ) ) ); 109 | } 110 | 111 | /*-------------------------------------------------------------------*/ 112 | /*! 113 | 114 | */ 115 | SampleView::~SampleView() 116 | { 117 | //std::cerr << "delete SampleView" << std::endl; 118 | } 119 | 120 | /*-------------------------------------------------------------------*/ 121 | /*! 122 | 123 | */ 124 | void 125 | SampleView::updateData() 126 | { 127 | std::shared_ptr< EditData > ptr = M_edit_data.lock(); 128 | if ( ! ptr 129 | || ! ptr->formationData() ) 130 | { 131 | return; 132 | } 133 | 134 | // 135 | // update samples 136 | // 137 | 138 | const int data_count = ptr->formationData()->dataCont().size(); 139 | 140 | while ( this->topLevelItemCount() > data_count ) 141 | { 142 | this->takeTopLevelItem( this->topLevelItemCount() - 1 ); 143 | } 144 | 145 | int idx = -1; 146 | for ( const rcsc::FormationData::Data & d : ptr->formationData()->dataCont() ) 147 | { 148 | ++idx; 149 | QTreeWidgetItem * item = this->topLevelItem( idx ); 150 | if ( ! item ) 151 | { 152 | item = new QTreeWidgetItem(); 153 | item->setFlags( Qt::ItemIsSelectable 154 | | Qt::ItemIsEditable 155 | | Qt::ItemIsDragEnabled 156 | //| Qt::ItemIsDropEnabled 157 | | Qt::ItemIsUserCheckable 158 | | Qt::ItemIsEnabled 159 | ); 160 | this->insertTopLevelItem( idx, item ); 161 | 162 | for ( size_t i = 0; i < d.players_.size(); ++i ) 163 | { 164 | QTreeWidgetItem * p = new QTreeWidgetItem(); 165 | p->setText( 0, tr( "p%1" ).arg( i + 1 ) ); 166 | //p->setData( 0, Qt::DisplayRole, tr( "p%1" ).arg( i + 1 ) ); 167 | p->setFlags( //Qt::ItemIsSelectable 168 | Qt::ItemIsEditable 169 | //| Qt::ItemIsDragEnabled 170 | //| Qt::ItemIsUserCheckable 171 | | Qt::ItemIsEnabled 172 | ); 173 | 174 | item->addChild( p ); 175 | } 176 | } 177 | 178 | item->setText( 0, QString::number( idx ) ); // visual index 179 | item->setText( 1, QString::number( d.ball_.x, 'f', 2 ) ); 180 | item->setText( 2, QString::number( d.ball_.y, 'f', 2 ) ); 181 | //item->setData( 0, Qt::DisplayRole, idx + 1 ); // visual index 182 | //item->setData( 1, Qt::EditRole, d.ball_.x ); 183 | //item->setData( 2, Qt::EditRole, d.ball_.y ); 184 | 185 | for ( size_t i = 0; i < d.players_.size(); ++i ) 186 | { 187 | QTreeWidgetItem * p = item->child( i ); 188 | if ( ! p ) 189 | { 190 | std::cerr << "SampleView::updateData " << idx 191 | << " player " << i + 1 << " not found" 192 | << std::endl; 193 | //p = new QTreeWidgetItem(); 194 | //p->setText( 0, QString::number( i + 1 ) ); 195 | //item->insertChild( i, p ); 196 | continue; 197 | } 198 | 199 | p->setText( 1, QString::number( d.players_[i].x, 'f', 2 ) ); 200 | p->setText( 2, QString::number( d.players_[i].y, 'f', 2 ) ); 201 | //p->setData( 1, Qt::EditRole, it->players_[i].x ); 202 | //p->setData( 2, Qt::EditRole, it->players_[i].y ); 203 | } 204 | } 205 | } 206 | 207 | /*-------------------------------------------------------------------*/ 208 | /*! 209 | 210 | */ 211 | void 212 | SampleView::selectSample( int idx ) 213 | { 214 | //std::cerr << "SampleView::selectDataIndex " << idx << std::endl; 215 | 216 | QTreeWidgetItem * item = this->topLevelItem( idx ); 217 | if ( item ) 218 | { 219 | // this->clearSelection(); 220 | // item->setSelected( true ); 221 | // this->scrollToItem( item ); 222 | this->setCurrentItem( item ); 223 | } 224 | else 225 | { 226 | this->setCurrentItem( static_cast< QTreeWidgetItem * >( 0 ) ); 227 | } 228 | } 229 | 230 | /*-------------------------------------------------------------------*/ 231 | /*! 232 | 233 | */ 234 | void 235 | SampleView::unselectData() 236 | { 237 | //std::cerr << "SampleView::unselectDataIndex" << std::endl; 238 | 239 | //this->clearSelection(); 240 | this->setCurrentItem( static_cast< QTreeWidgetItem * >( 0 ) ); 241 | } 242 | 243 | /*-------------------------------------------------------------------*/ 244 | /*! 245 | 246 | */ 247 | // Qt::DropActions 248 | // SampleView::supportedDropActions() const 249 | // { 250 | // return Qt::MoveAction; 251 | // } 252 | 253 | /*-------------------------------------------------------------------*/ 254 | /*! 255 | 256 | */ 257 | void 258 | SampleView::contextMenuEvent( QContextMenuEvent * event ) 259 | { 260 | QTreeWidgetItem * item = this->itemAt( event->pos() ); 261 | 262 | if ( ! item ) 263 | { 264 | return; 265 | } 266 | 267 | if ( item->parent() ) 268 | { 269 | std::cerr << "contextMenuEvent clicked item has parent." << std::endl; 270 | return; 271 | } 272 | 273 | if ( ! item->isSelected() ) 274 | { 275 | // this->clearSelection(); 276 | // item->setSelected( true ); 277 | this->setCurrentItem( item ); 278 | } 279 | 280 | std::cerr << "SampleView::contextMenuEvent " 281 | << event->pos().x() << ',' << event->pos().y() 282 | << " item: idx=" << item->text( 0 ).toStdString() 283 | << " value=" << item->text( 1 ).toStdString() 284 | << std::endl; 285 | 286 | QMenu menu( this ); 287 | menu.addAction( tr( "Change Index" ), this, SLOT( menuChangeSampleIndex() ) ); 288 | menu.addAction( tr( "Delete" ), this, SLOT( menuDeleteSample() ) ); 289 | 290 | menu.exec( event->globalPos() ); 291 | } 292 | 293 | /*-------------------------------------------------------------------*/ 294 | /*! 295 | 296 | */ 297 | void 298 | SampleView::dropEvent( QDropEvent * event ) 299 | { 300 | //std::cerr << "dropEvent action=" << std::hex << event->dropAction() 301 | // << " possibleActions=" << std::hex << event->possibleActions() 302 | // << " proposedAction=" << std::hex << event->proposedAction() 303 | // << "\n pos=" << event->pos().x() << ',' << event->pos().y() 304 | // << std::endl; 305 | 306 | QTreeWidgetItem * moving = this->currentItem(); 307 | if ( ! moving ) 308 | { 309 | event->ignore(); 310 | return; 311 | } 312 | 313 | QTreeWidgetItem * dest = this->itemAt( event->pos() ); 314 | if ( ! dest ) 315 | { 316 | event->ignore(); 317 | return; 318 | } 319 | 320 | if ( this->dropIndicatorPosition() == QAbstractItemView::AboveItem ) 321 | { 322 | int dest_index = this->indexOfTopLevelItem( dest ); 323 | if ( dest_index > 0 ) 324 | { 325 | dest = this->topLevelItem( dest_index - 1 ); 326 | if ( ! dest ) 327 | { 328 | event->ignore(); 329 | return; 330 | } 331 | } 332 | } 333 | 334 | if ( moving == dest ) 335 | { 336 | event->ignore(); 337 | return; 338 | } 339 | 340 | if ( moving->parent() != dest->parent() ) 341 | { 342 | event->ignore(); 343 | return; 344 | } 345 | 346 | event->ignore(); 347 | 348 | //std::cerr << " moving item = " << moving->text( 0 ).toStdString() 349 | // << " , " << moving->text( 1 ).toStdString() 350 | // << "\n dest=" << dest->text( 0 ).toStdString() 351 | // << " , " << dest->text( 1 ).toStdString() 352 | // << std::endl; 353 | 354 | if ( ! moving->parent() ) 355 | { 356 | int visual_moving_index = this->indexOfTopLevelItem( moving ) + 1; 357 | int visual_dest_index = this->indexOfTopLevelItem( dest ) + 1; 358 | 359 | emit sampleIndexChangeRequested( visual_moving_index, visual_dest_index ); 360 | } 361 | 362 | //QTreeWidget::dropEvent( event ); 363 | } 364 | 365 | 366 | /*-------------------------------------------------------------------*/ 367 | /*! 368 | 369 | */ 370 | // bool 371 | // SampleView::dropMimeData( QTreeWidgetItem * parent, 372 | // int index, 373 | // const QMimeData * data, 374 | // Qt::DropAction action ) 375 | // { 376 | // std::cerr << "drpMimeData parent=" << parent->text( 0 ).toStdString() 377 | // << " index=" << index 378 | // << " mimeData=" << data->text().toStdString() 379 | // << " action=" << action 380 | // << std::endl; 381 | 382 | // return QTreeWidget::dropMimeData( parent, index, data, action ); 383 | // } 384 | 385 | /*-------------------------------------------------------------------*/ 386 | /*! 387 | 388 | */ 389 | void 390 | SampleView::setCurrentData( QTreeWidgetItem * current ) 391 | { 392 | int idx = this->indexOfTopLevelItem( current ); 393 | if ( 0 <= idx ) 394 | { 395 | emit sampleSelected( idx ); 396 | } 397 | } 398 | 399 | /*-------------------------------------------------------------------*/ 400 | /*! 401 | 402 | */ 403 | void 404 | SampleView::menuChangeSampleIndex() 405 | { 406 | std::shared_ptr< EditData > ptr = M_edit_data.lock(); 407 | if ( ! ptr 408 | || ! ptr->formationData() ) 409 | { 410 | return; 411 | } 412 | 413 | QTreeWidgetItem * item = this->currentItem(); 414 | if ( ! item ) 415 | { 416 | return; 417 | } 418 | 419 | int idx = this->indexOfTopLevelItem( item ); 420 | if ( 0 <= idx ) 421 | { 422 | const int data_size = ptr->formationData()->dataCont().size(); 423 | if ( data_size == 0 ) 424 | { 425 | return; 426 | } 427 | 428 | int visual_idx = idx + 1; 429 | bool ok = false; 430 | int new_visual_idx = QInputDialog::getInt( this, 431 | tr( "Select New Index" ), 432 | tr( "New Index" ), 433 | visual_idx, // default 434 | 1, // min 435 | data_size, // max 436 | 1, // step 437 | &ok ); 438 | if ( ok ) 439 | { 440 | if ( visual_idx == new_visual_idx ) 441 | { 442 | return; 443 | } 444 | 445 | emit sampleIndexChangeRequested( visual_idx, new_visual_idx ); 446 | } 447 | } 448 | } 449 | 450 | /*-------------------------------------------------------------------*/ 451 | /*! 452 | 453 | */ 454 | void 455 | SampleView::menuDeleteSample() 456 | { 457 | QTreeWidgetItem * item = this->currentItem(); 458 | if ( item ) 459 | { 460 | int idx = this->indexOfTopLevelItem( item ); 461 | if ( 0 <= idx ) 462 | { 463 | emit sampleDeleteRequested( idx ); 464 | } 465 | } 466 | } 467 | 468 | /*-------------------------------------------------------------------*/ 469 | /*! 470 | 471 | */ 472 | // void 473 | // SampleView::doubleClickItem( QTreeWidgetItem * item, 474 | // int column ) 475 | // { 476 | // if ( column != 1 ) 477 | // { 478 | // return; 479 | // } 480 | 481 | // if ( ! item->parent() ) 482 | // { 483 | // //std::cerr << "SampleView::doubleClickItem topLevelItem" << std::endl; 484 | // return; 485 | // } 486 | 487 | // std::cerr << "SampleView::doubleClickItem " << item->text( 0 ).toStdString() 488 | // << " , " << item->text( 1 ).toStdString() 489 | // << std::endl; 490 | 491 | // editItem( item, 1 ); 492 | // //openPersistentEditor( item, 1 ); 493 | // } 494 | 495 | 496 | /*-------------------------------------------------------------------*/ 497 | /*! 498 | 499 | */ 500 | void 501 | SampleView::changeCoordinates( const QModelIndex & index, 502 | double value ) 503 | { 504 | std::cerr << "SampleView::changeCoordinates " 505 | << " index=" << index.row() << ',' << index.column() 506 | << " value=" << value 507 | << std::endl; 508 | QTreeWidgetItem * item = this->itemFromIndex( index ); 509 | 510 | if ( item ) 511 | { 512 | if ( ! item->parent() ) // no parent == root item 513 | { 514 | // ball 515 | int idx = this->indexOfTopLevelItem( item ); 516 | if ( 0 <= idx ) 517 | { 518 | double x = 0.0, y = 0.0; 519 | if ( index.column() == 1 ) 520 | { 521 | x = value; 522 | y = item->text( 2 ).toDouble(); 523 | } 524 | else if ( index.column() == 2 ) 525 | { 526 | x = item->text( 1 ).toDouble(); 527 | y = value; 528 | } 529 | else 530 | { 531 | std::cerr << __FILE__ << ':' << __LINE__ << ':' 532 | << " Illegal column count" 533 | << std::endl; 534 | return; 535 | } 536 | 537 | emit ballReplaced( idx, x, y ); 538 | } 539 | } 540 | else if ( item->parent() 541 | && ! item->parent()->parent() ) 542 | { 543 | // players 544 | int idx = this->indexOfTopLevelItem( item->parent() ); 545 | if ( 0 <= idx ) 546 | { 547 | int unum = item->text( 0 ).mid( 1 ).toInt(); 548 | 549 | double x = 0.0, y = 0.0; 550 | if ( index.column() == 1 ) 551 | { 552 | x = value; 553 | y = item->text( 2 ).toDouble(); 554 | } 555 | else if ( index.column() == 2 ) 556 | { 557 | x = item->text( 1 ).toDouble(); 558 | y = value; 559 | } 560 | else 561 | { 562 | std::cerr << __FILE__ << ':' << __LINE__ << ':' 563 | << " Illegal column count" 564 | << std::endl; 565 | return; 566 | } 567 | 568 | emit playerReplaced( idx, unum, x, y ); 569 | } 570 | } 571 | } 572 | 573 | } 574 | 575 | /*-------------------------------------------------------------------*/ 576 | /*! 577 | 578 | */ 579 | // void 580 | // SampleView::closeEditor( QWidget * editor, 581 | // QAbstractItemDelegate::EndEditHint hint ) 582 | // { 583 | // std::cerr << "SampleView::closeEditor hint=" //<< hint 584 | // << std::endl; 585 | // QTreeWidget::closeEditor( editor, hint ); 586 | // } 587 | -------------------------------------------------------------------------------- /src/edit_dialog.cpp: -------------------------------------------------------------------------------- 1 | // -*-c++-*- 2 | 3 | /*! 4 | \file edit_dialog.cpp 5 | \brief Formation editor position edit Dialog class Source File. 6 | */ 7 | 8 | /* 9 | *Copyright: 10 | 11 | Copyright (C) Hidehisa AKIYAMA 12 | 13 | This code is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2, or (at your option) 16 | any later version. 17 | 18 | This code is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this code; see the file COPYING. If not, write to 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 26 | 27 | *EndCopyright: 28 | */ 29 | 30 | ///////////////////////////////////////////////////////////////////// 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | 38 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "edit_dialog.h" 45 | 46 | #include "edit_data.h" 47 | #include "options.h" 48 | 49 | #include 50 | 51 | /*-------------------------------------------------------------------*/ 52 | /*! 53 | 54 | */ 55 | EditDialog::EditDialog( QWidget * parent ) 56 | : QDialog( parent ) 57 | { 58 | this->setWindowTitle( tr( "Edit Dialog" ) ); 59 | 60 | createWidgets(); 61 | updateData(); 62 | } 63 | 64 | /*-------------------------------------------------------------------*/ 65 | /*! 66 | 67 | */ 68 | EditDialog::~EditDialog() 69 | { 70 | //std::cerr << "delete EditDialog" << std::endl; 71 | } 72 | 73 | /*-------------------------------------------------------------------*/ 74 | /*! 75 | 76 | */ 77 | void 78 | EditDialog::createWidgets() 79 | { 80 | QVBoxLayout * top_vbox = new QVBoxLayout(); 81 | top_vbox->setMargin( 2 ); 82 | top_vbox->setSpacing( 2 ); 83 | top_vbox->setSizeConstraint( QLayout::SetFixedSize ); 84 | 85 | // method name 86 | { 87 | QHBoxLayout * layout = new QHBoxLayout(); 88 | top_vbox->addLayout( layout ); 89 | 90 | //layout->addStretch( 1 ); 91 | { 92 | QLabel * label = new QLabel( tr( "Type Name " ) ); 93 | label->setAlignment( Qt::AlignCenter ); 94 | layout->addWidget( label, 95 | 1, 96 | Qt::AlignLeft | Qt::AlignVCenter ); 97 | } 98 | //layout->addSpacing( 4 ); 99 | { 100 | M_type_name = new QLineEdit( tr( "---" ) ); 101 | M_type_name->setMinimumWidth( this->fontMetrics().width( "DelaunayTriangulationXXXX" ) + 4 ); 102 | M_type_name->setReadOnly( true ); // no editable 103 | M_type_name->setEnabled( false ); // no editable 104 | 105 | layout->addWidget( M_type_name, 106 | 1, 107 | Qt::AlignCenter ); 108 | } 109 | layout->addStretch( 1 ); 110 | } 111 | 112 | // ball info 113 | { 114 | QHBoxLayout * layout = new QHBoxLayout(); 115 | top_vbox->addLayout( layout ); 116 | 117 | //layout->addStretch( 1 ); 118 | { 119 | QLabel * label = new QLabel( tr( "Ball" ) ); 120 | label->setMaximumSize( 40, this->fontMetrics().height() + 12 ); 121 | layout->addWidget( label, 0, Qt::AlignCenter ); 122 | } 123 | //layout->addStretch( 1 ); 124 | { 125 | QLabel * label = new QLabel( tr( " X:" ) ); 126 | label->setMaximumSize( 24, this->fontMetrics().height() + 12 ); 127 | layout->addWidget( label, 0, Qt::AlignLeft | Qt::AlignVCenter ); 128 | } 129 | { 130 | M_ball_pos_x = new QLineEdit( tr( "0" ) ); 131 | M_ball_pos_x->setMinimumSize( 48, 24 ); 132 | M_ball_pos_x->setMaximumSize( 64, 24 ); 133 | M_ball_pos_x->setValidator( new QDoubleValidator( -57.5, 57.5, 2, M_ball_pos_x ) ); 134 | connect( M_ball_pos_x, SIGNAL( editingFinished() ), 135 | this, SLOT( validateBallCoordinate() ) ); 136 | layout->addWidget( M_ball_pos_x, 0, Qt::AlignLeft | Qt::AlignVCenter ); 137 | } 138 | //layout->addStretch( 1 ); 139 | { 140 | QLabel * label = new QLabel( tr( " Y:" ) ); 141 | label->setMaximumSize( 24, this->fontMetrics().height() + 12 ); 142 | layout->addWidget( label, 0, Qt::AlignLeft | Qt::AlignVCenter ); 143 | } 144 | { 145 | M_ball_pos_y = new QLineEdit( tr( "0" ) ); 146 | M_ball_pos_y->setMinimumSize( 48, 24 ); 147 | M_ball_pos_y->setMaximumSize( 64, 24 ); 148 | M_ball_pos_y->setValidator( new QDoubleValidator( -39.0, 39.0, 2, M_ball_pos_y ) ); 149 | connect( M_ball_pos_y, SIGNAL( editingFinished() ), 150 | this, SLOT( validateBallCoordinate() ) ); 151 | layout->addWidget( M_ball_pos_y, 0, Qt::AlignLeft | Qt::AlignVCenter ); 152 | } 153 | layout->addStretch( 1 ); 154 | } 155 | 156 | { 157 | const int unum_width = this->fontMetrics().width( tr( "Unum" ) ) + 4; 158 | const int pair_width = this->fontMetrics().width( tr( "0000" ) ) + 4; 159 | const int role_width = this->fontMetrics().width( tr( "CenterForwardXXXX" ) ) + 4; 160 | const int coord_width = this->fontMetrics().width( tr( "-00.0000" ) ) + 4; 161 | // const int marker_width = this->fontMetrics().width( tr( "SPM" ) ) + 4; 162 | // const int smarker_width = this->fontMetrics().width( tr( "SPM" ) ) + 4; 163 | 164 | QGridLayout * layout = new QGridLayout(); 165 | top_vbox->addLayout( layout ); 166 | 167 | layout->setMargin( 1 ); 168 | layout->setSpacing( 0 ); 169 | layout->setColumnMinimumWidth( 0, unum_width ); 170 | layout->setColumnMinimumWidth( 1, pair_width ); 171 | // layout->setColumnMinimumWidth( 5, marker_width ); 172 | // layout->setColumnMinimumWidth( 6, smarker_width ); 173 | 174 | // header 175 | int row = 0; 176 | int col = 0; 177 | layout->addWidget( new QLabel( tr( "Unum" ) ), 0, col, Qt::AlignCenter ); ++col; 178 | { 179 | QLabel * l = new QLabel( tr( "Pair" ) ); 180 | l->setToolTip( tr( "Paired Number" ) ); 181 | layout->addWidget( l, 0, col, Qt::AlignCenter ); ++col; 182 | } 183 | layout->addWidget( new QLabel( tr( "Type" ) ), 0, col, Qt::AlignCenter ); ++col; 184 | layout->addWidget( new QLabel( tr( "Side" ) ), 0, col, Qt::AlignCenter ); ++col; 185 | layout->addWidget( new QLabel( tr( "Role Name" ) ), 0, col, Qt::AlignCenter ); ++col; 186 | layout->addWidget( new QLabel( tr( "X" ) ), 0, col, Qt::AlignCenter ); ++col; 187 | layout->addWidget( new QLabel( tr( "Y" ) ), 0, col, Qt::AlignCenter ); ++col; 188 | // { 189 | // QLabel * l = new QLabel( tr( "M" ) ); 190 | // l->setToolTip( tr( "Marker Type" ) ); 191 | // layout->addWidget( l, 0, col, Qt::AlignCenter ); ++col; 192 | // } 193 | // { 194 | // QLabel * l = new QLabel( tr( "SPM" ) ); 195 | // l->setToolTip( tr( "SetPlay Marker Type" ) ); 196 | // layout->addWidget( l, 0, col, Qt::AlignCenter ); ++col; 197 | // } 198 | 199 | row = 1; 200 | for ( int i = 0; i < 11; ++i, ++row ) 201 | { 202 | col = 0; 203 | QLabel * label = new QLabel( tr( "%1" ).arg( i + 1 ) ); 204 | label->setAlignment( Qt::AlignCenter ); 205 | label->setMinimumSize( unum_width, 24 ); 206 | label->setMaximumSize( unum_width + 8, 24 ); 207 | layout->addWidget( label, row, col, Qt::AlignCenter ); 208 | ++col; 209 | 210 | M_paired_number[i] = new QLineEdit( tr( "0" ) ); 211 | M_paired_number[i]->setMinimumSize( pair_width, 24 ); 212 | M_paired_number[i]->setMaximumSize( pair_width, 24 ); 213 | M_paired_number[i]->setValidator( new QIntValidator( -1, 11, M_paired_number[i] ) ); 214 | layout->addWidget( M_paired_number[i], row, col, Qt::AlignCenter ); 215 | ++col; 216 | 217 | M_role_type[i] = new QComboBox(); 218 | M_role_type[i]->addItem( tr( "G" ) ); 219 | M_role_type[i]->addItem( tr( "DF" ) ); 220 | M_role_type[i]->addItem( tr( "MF" ) ); 221 | M_role_type[i]->addItem( tr( "FW" ) ); 222 | layout->addWidget( M_role_type[i], row, col, Qt::AlignCenter ); 223 | ++col; 224 | 225 | M_role_side[i] = new QComboBox(); 226 | M_role_side[i]->addItem( tr( "C" ) ); 227 | M_role_side[i]->addItem( tr( "L" ) ); 228 | M_role_side[i]->addItem( tr( "R" ) ); 229 | layout->addWidget( M_role_side[i], row, col, Qt::AlignCenter ); 230 | ++col; 231 | 232 | M_role_name[i] = new QLineEdit( tr( "Role" ) ); 233 | M_role_name[i]->setMaximumSize( role_width, 24 ); 234 | layout->addWidget( M_role_name[i], row, col, Qt::AlignCenter ); 235 | ++col; 236 | 237 | M_pos_x[i] = new QLineEdit( tr( "0.0" ) ); 238 | M_pos_x[i]->setMaximumSize( coord_width, 24 ); 239 | M_pos_x[i]->setValidator( new QDoubleValidator( -57.5, 57.5, 2, M_pos_x[i] ) ); 240 | layout->addWidget( M_pos_x[i], row, col, Qt::AlignCenter ); 241 | ++col; 242 | 243 | M_pos_y[i] = new QLineEdit( tr( "0.0" ) ); 244 | M_pos_y[i]->setMaximumSize( coord_width, 24 ); 245 | M_pos_y[i]->setValidator( new QDoubleValidator( -39.0, 39.0, 2, M_pos_y[i] ) ); 246 | layout->addWidget( M_pos_y[i], row, col, Qt::AlignCenter ); 247 | ++col; 248 | 249 | // M_marker[i] = new QCheckBox(); 250 | // layout->addWidget( M_marker[i], row, col, Qt::AlignCenter ); 251 | // ++col; 252 | 253 | // M_setplay_marker[i] = new QCheckBox(); 254 | // layout->addWidget( M_setplay_marker[i], row, col, Qt::AlignCenter ); 255 | // ++col; 256 | } 257 | } 258 | 259 | { 260 | QHBoxLayout * layout = new QHBoxLayout(); 261 | top_vbox->addLayout( layout ); 262 | 263 | { 264 | QPushButton * btn = new QPushButton( tr( "Apply" ) ); 265 | //btn->setAutoDefault( false ); 266 | connect( btn, SIGNAL( clicked() ), 267 | this, SLOT( applyToField() ) ); 268 | layout->addWidget( btn, 0, Qt::AlignLeft ); 269 | } 270 | layout->addStretch( 1 ); 271 | { 272 | QPushButton * btn = new QPushButton( tr( "Reset" ) ); 273 | btn->setAutoDefault( false ); 274 | btn->setDefault( false ); 275 | connect( btn, SIGNAL( clicked() ), 276 | this, SLOT( resetChanges() ) ); 277 | layout->addWidget( btn, 0, Qt::AlignRight ); 278 | } 279 | { 280 | QPushButton * btn = new QPushButton( tr( "Close" ) ); 281 | btn->setAutoDefault( false ); 282 | btn->setDefault( false ); 283 | connect( btn, SIGNAL( clicked() ), 284 | this, SLOT( close() ) ); 285 | layout->addWidget( btn, 0, Qt::AlignRight ); 286 | } 287 | } 288 | 289 | this->setLayout( top_vbox ); 290 | } 291 | 292 | /*-------------------------------------------------------------------*/ 293 | /*! 294 | 295 | */ 296 | void 297 | EditDialog::showEvent( QShowEvent * event ) 298 | { 299 | QDialog::showEvent( event ); 300 | 301 | updateData(); 302 | } 303 | 304 | /*-------------------------------------------------------------------*/ 305 | /*! 306 | 307 | */ 308 | void 309 | EditDialog::closeEvent( QCloseEvent * event ) 310 | { 311 | event->accept(); 312 | emit shown( false ); 313 | } 314 | 315 | /*-------------------------------------------------------------------*/ 316 | /*! 317 | 318 | */ 319 | void 320 | EditDialog::updateData() 321 | { 322 | if ( ! this->isVisible() ) 323 | { 324 | return; 325 | } 326 | 327 | std::shared_ptr< EditData > ptr = M_edit_data.lock(); 328 | if ( ! ptr ) 329 | { 330 | return; 331 | } 332 | 333 | rcsc::Formation::ConstPtr f = ptr->formation(); 334 | if ( ! f ) 335 | { 336 | std::cerr << "EditDialog. no formation data" << std::endl; 337 | return; 338 | } 339 | M_type_name->setText( QString::fromStdString( f->methodName() ) ); 340 | 341 | 342 | M_type_name->setText( QString::fromStdString( f->methodName() ) ); 343 | 344 | // ball info 345 | const rcsc::FormationData::Data & s = ptr->currentState(); 346 | 347 | M_ball_pos_x->setText( QString::number( s.ball_.x, 'f', 2 ) ); 348 | M_ball_pos_y->setText( QString::number( s.ball_.y, 'f', 2 ) ); 349 | 350 | // player info 351 | 352 | Q_ASSERT( s.players_.size() == 11 ); 353 | 354 | for ( size_t i = 0; i < 11; ++i ) 355 | { 356 | int unum = i + 1; 357 | M_paired_number[i]->setText( QString::number( f->pairedNumber( unum ) ) ); 358 | 359 | const rcsc::RoleType role_type = f->roleType( unum ); 360 | M_role_type[i]->setCurrentIndex( static_cast< int >( role_type.type() ) ); 361 | M_role_side[i]->setCurrentIndex( role_type.side() == rcsc::RoleType::Left 362 | ? 1 363 | : role_type.side() == rcsc::RoleType::Right 364 | ? 2 365 | : 0 ); 366 | M_role_name[i]->setText( QString::fromStdString( f->roleName( unum ) ) ); 367 | 368 | M_pos_x[i]->setText( QString::number( s.players_[i].x, 'f', 2 ) ); 369 | M_pos_y[i]->setText( QString::number( s.players_[i].y, 'f', 2 ) ); 370 | 371 | // M_marker[i]->setCheckState( f->isMarker( unum ) 372 | // ? Qt::Checked 373 | // : Qt::Unchecked ); 374 | // M_setplay_marker[i]->setCheckState( f->isSetPlayMarker( unum ) 375 | // ? Qt::Checked 376 | // : Qt::Unchecked ); 377 | } 378 | } 379 | 380 | /*-------------------------------------------------------------------*/ 381 | /*! 382 | 383 | */ 384 | void 385 | EditDialog::validateBallCoordinate() 386 | { 387 | QLineEdit * editor = qobject_cast< QLineEdit * >( sender() ); 388 | bool ok = false; 389 | double value = editor->text().toDouble( &ok ); 390 | if ( ok ) 391 | { 392 | if ( value != 0.0 393 | && std::fabs( value ) < 0.5 ) 394 | { 395 | value = rint( value * 2.0 ) * 0.5; 396 | editor->setText( QString::number( value, 'f', 2 ) ); 397 | } 398 | } 399 | } 400 | 401 | /*-------------------------------------------------------------------*/ 402 | /*! 403 | 404 | */ 405 | void 406 | EditDialog::resetChanges() 407 | { 408 | updateData(); 409 | } 410 | 411 | /*-------------------------------------------------------------------*/ 412 | bool 413 | EditDialog::checkConsistency() 414 | { 415 | for ( int num = 1; num <= 11; ++num ) 416 | { 417 | bool ok = false; 418 | const int paired_number = M_paired_number[num-1]->text().toInt( &ok ); 419 | if ( ! ok ) return false; 420 | if ( paired_number == num ) 421 | { 422 | std::cerr << "(EditDialog) ERROR: number(" << num << ") == paired_number(" << paired_number << ")" << std::endl; 423 | return false; 424 | } 425 | 426 | if ( 1 <= paired_number && paired_number <= 11 ) 427 | { 428 | const int n = M_paired_number[paired_number-1]->text().toInt( &ok ); 429 | if ( ! ok ) return false; 430 | if ( n != num ) 431 | { 432 | std::cerr << "(EditDialog) ERROR: number(" << num << ") != paired(" << n << ")" << std::endl; 433 | return false; 434 | } 435 | 436 | if ( M_role_side[num-1]->currentText() == "C" ) 437 | { 438 | std::cerr << "(EditDialog) ERROR: Center type has a paired number(" << paired_number << ")" << std::endl; 439 | return false; 440 | } 441 | 442 | if ( M_role_side[num-1]->currentText() == M_role_side[paired_number-1]->currentText() ) 443 | { 444 | std::cerr << "(EditDialog) ERROR: paired players(" << num << "," << paired_number << ") have same side" << std::endl; 445 | return false; 446 | } 447 | } 448 | 449 | if ( M_role_name[num-1]->text().isEmpty() ) 450 | { 451 | std::cerr << "(EditDialog) ERROR: empty role name" << std::endl; 452 | return false; 453 | } 454 | } 455 | 456 | return true; 457 | } 458 | 459 | /*-------------------------------------------------------------------*/ 460 | /*! 461 | 462 | */ 463 | void 464 | EditDialog::applyToField() 465 | { 466 | if ( ! checkConsistency() ) 467 | { 468 | QMessageBox::warning( this, 469 | tr( "Error" ), 470 | tr( "Illegal data detected." ), 471 | QMessageBox::Ok, 472 | QMessageBox::NoButton ); 473 | return; 474 | } 475 | 476 | std::shared_ptr< EditData > ptr = M_edit_data.lock(); 477 | if ( ! ptr ) 478 | { 479 | std::cerr << "(EditDialog::applyToField) no data" << std::endl; 480 | return; 481 | } 482 | 483 | bool data_auto_select = Options::instance().dataAutoSelect(); 484 | bool player_auto_move = Options::instance().playerAutoMove(); 485 | bool pair_mode = Options::instance().pairMode(); 486 | Options::instance().setDataAutoSelect( false ); 487 | Options::instance().setPlayerAutoMove( false ); 488 | Options::instance().setPairMode( false ); 489 | 490 | // ball 491 | { 492 | bool ok_x = false; 493 | bool ok_y = false; 494 | double x = M_ball_pos_x->text().toDouble( &ok_x ); 495 | double y = M_ball_pos_y->text().toDouble( &ok_y ); 496 | if ( ok_x && ok_y ) 497 | { 498 | ptr->moveBallTo( x, y ); 499 | } 500 | } 501 | 502 | // players 503 | for ( int unum = 1; unum <= 11; ++unum ) 504 | { 505 | bool ok = false; 506 | const int paired_number = M_paired_number[unum-1]->text().toInt( &ok ); 507 | if ( ! ok ) 508 | { 509 | std::cerr << "(EditDialog::applyToField) Invalid pair number." << std::endl; 510 | continue; 511 | } 512 | 513 | std::string role_name = M_role_name[unum-1]->text().toStdString(); 514 | if ( role_name.empty() ) 515 | { 516 | std::cerr << __FILE__ << ':' << __LINE__ 517 | << " *** ERROR *** Empty role name." 518 | << std::endl; 519 | } 520 | else 521 | { 522 | ptr->updateRoleData( unum, paired_number, role_name ); 523 | } 524 | 525 | bool ok_x = false; 526 | bool ok_y = false; 527 | double x = M_pos_x[unum-1]->text().toDouble( &ok_x ); 528 | double y = M_pos_y[unum-1]->text().toDouble( &ok_y ); 529 | if ( ok_x && ok_y ) 530 | { 531 | ptr->movePlayerTo( unum, x, y ); 532 | } 533 | 534 | ptr->updateRoleType( unum, 535 | M_role_type[unum-1]->currentIndex(), 536 | M_role_side[unum-1]->currentIndex() ); 537 | 538 | // ptr->updateMarkerData( unum, 539 | // ( M_marker[unum-1]->checkState() == Qt::Checked ), 540 | // ( M_setplay_marker[unum-1]->checkState() == Qt::Checked ) ); 541 | } 542 | 543 | updateData(); 544 | 545 | Options::instance().setDataAutoSelect( data_auto_select ); 546 | Options::instance().setPlayerAutoMove( player_auto_move ); 547 | Options::instance().setPairMode( pair_mode ); 548 | 549 | emit viewUpdated(); 550 | 551 | } 552 | --------------------------------------------------------------------------------