2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
14 #include <boost/enable_shared_from_this.hpp>
16 #include <core/state_fwd.h>
18 #include "entitytoken.h"
20 class ActionCollection
;
29 * @b Controller is the base abstract class for all controllers in Tagua.
30 * Tagua can be used in different modes, such as game editing or position editing.
31 * Each mode corresponds to a concrete subclass of Controller, and defines its behaviour
32 * in response to user events (history navigation, move executions...).
33 * By default, events are routed to the user entity returned by the virtual function
36 class Controller
: public boost::enable_shared_from_this
<Controller
> {
39 virtual boost::shared_ptr
<UserEntity
> entity() const = 0;
41 Controller(ChessTable
* view
);
42 virtual ~Controller();
45 * Variant specific actions.
47 virtual ActionCollection
* variantActions() const = 0;
50 * Variant associated to the controller.
52 virtual QString
variant() const = 0;
55 * Terminate activity, create another controller and delegate everything to it.
56 * @return The delegate controller, or simply @b this if controller does not need
59 virtual boost::shared_ptr
<Controller
> end() { return shared_from_this(); }
62 * Detach from resources without disposing them.
64 virtual void detach() { }
67 * Clear board. Undefined for almost all controllers.
68 * @return Whether the action has been successfully executed.
70 virtual bool clearBoard() { return false; }
73 * Set starting position on the board. Undefined for almost all controllers.
74 * @return Whether the action has been successfully executed.
76 virtual bool setStartingPosition() { return false; }
79 * Set a position on the board. Undefined for almost all controllers.
80 * @param fen The position to be set, in FEN notation.
81 * @return Whether the action has been successfully executed.
83 virtual bool setFEN(const QString
&) { return false; }
86 * Get a FEN string representing the current position on the board.
88 virtual QString
fen() { return ""; }
91 * @return current position, or a null shared_ptr if no current position
92 * concept is defined for this controller.
94 virtual StatePtr
currentPosition() const { return StatePtr(); }
97 * Change turn. Used for example in edit position mode.
99 virtual void setTurn(int) { }
102 * Forward a movelist undo call.
107 * Forward a movelist redo call.
112 * Forward a movelist truncate call.
114 virtual bool truncate();
117 * Forward a movelist promote variation call.
119 virtual bool promoteVariation();
122 * Navigate back in history.
127 * Navigate forward in history.
129 virtual bool forward();
132 * Warp to the beginning of the history.
134 virtual void gotoFirst();
137 * Warp to the end of the history.
139 virtual void gotoLast();
144 virtual QString
save();
147 * Load game from a PGN.
149 virtual void loadPGN(const PGN
&);
152 * Create a CTRL Action.
153 * @sa UI::createCtrlAction
155 virtual void createCtrlAction() { }
158 * Destroy a CTRL Action.
159 * @sa UI::createCtrlAction.
161 virtual void destroyCtrlAction() { };
164 * Let an engine play as player @a side.
165 * @return a token which uniquely identifies the engine entity
166 * and can be used to remove it from the entity list.
168 virtual EntityToken
addPlayingEngine(const IColor
* /*side*/,
169 const boost::shared_ptr
<Engine
>&) { return EntityToken(); }
172 * Remove an entity from the controller list.
174 virtual void removeEntity(const EntityToken
&) { }
176 virtual void reloadSettings() = 0;
179 * Set owning user interface.
180 * Used to setup callbacks towards the main window, like action state
181 * change notifications.
183 virtual void setUI(UI
& ui
) = 0;
186 * Called whenever a controller becomes active in the main window.
188 virtual void activate() = 0;