creativity  v1.3.0
Agent-based model of creativity and piracy
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
creativity::gui::GUI Class Reference

Class that runs a GUI in a thread, collecting its events into a queue to be processed periodically (e.g. More...

#include <creativity/gui/GUI.hpp>

Classes

class  Event
 Simple class containing event information. More...
 
struct  Parameter
 The parameter struct for passing a configured value back from the GUI. More...
 

Public Types

enum  ParamType { ParamType::save_as, ParamType::load, ParamType::seed, ParamType::threads }
 Parameter types for a Parameter. More...
 

Public Member Functions

 GUI (Creativity &creativity, std::function< void(Parameter param)> configure, std::function< void()> initialize, std::function< void(eris::eris_time_t end)> change_periods, std::function< void()> run, std::function< void()> stop, std::function< void()> step, std::function< void()> quit)
 Creates a new GUI object. More...
 
void start (const cmdargs::GUI &args)
 Starts the GUI, reading the glade file and starting the GUI thread.
 
void checkEvents ()
 Checks whether the GUI has generated any events and, if so, processes them. More...
 
void waitEvents ()
 If the GUI has queued events, processes them. More...
 
void newStates (eris::eris_time_t switch_to=(eris::eris_time_t) -1)
 Signals the GUI thread that one or more states have been completed. More...
 
void initialized ()
 Sends a signal to the GUI thread that the simulation setup is complete. More...
 
void running ()
 Sends a signal to the GUI thread that the simulation has started or resumed running. More...
 
void progress (eris::eris_time_t t, eris::eris_time_t end, double speed)
 Signals the GUI thread of a progress update. More...
 
void stopped (bool more)
 Sends a signal to the GUI thread that the simulation has stopped running. More...
 
void error (std::string message)
 Sends a signal to the GUI thread that an error has occurred. More...
 
void waitForEvent (Event::Type t)
 Processes events sent by the GUI until at least one event of the given type has been received.
 

Static Public Member Functions

static std::string pos_to_string (const eris::Position &pos)
 Utility method used by various GUI classes to convert a Position to a user-displayable string.
 

Friends

class GraphArea
 

Detailed Description

Class that runs a GUI in a thread, collecting its events into a queue to be processed periodically (e.g.

between iterations) via GUIShim.

Member Enumeration Documentation

§ ParamType

Parameter types for a Parameter.

Enumerator
save_as 

The file to save simulation data to (will be overwritten)

load 

The file to load existing simulation data from.

seed 

Sets the seed value for eris::random::seed in .ul

threads 

Number of threads to use in .ul

Constructor & Destructor Documentation

§ GUI()

creativity::gui::GUI::GUI ( Creativity creativity,
std::function< void(Parameter param)>  configure,
std::function< void()>  initialize,
std::function< void(eris::eris_time_t end)>  change_periods,
std::function< void()>  run,
std::function< void()>  stop,
std::function< void()>  step,
std::function< void()>  quit 
)

Creates a new GUI object.

The GUI is not set up and started until the start() method is called.

Parameters
creativityThe Creativity object containing the simulation storage. The object does not need to be initialized (by calling setup()): in particular, if the GUI is displaying a previously stored simulation run, it typically won't be.

Note that the creativity object must persist as long as the created GUI object.

Parameters
configureA function to call with GUI simulation parameters when the user configures the simulation via the GUI. Note that this doesn't include simulation settings (like the number of readers)–those are set directly in the settings object.

If the simulation cannot be started (for example, because some parameters are invalid) the function should throw an exception derived from std::exception; the .what() value of the exception will be displayed to the user as an error message.

Parameters
initializeA function to call to initialize the simulation without starting it. If something goes wrong, this should throw an exception derived from std::exception: the .what() value of the exception will be displayed to the user as an error message.
change_periodsA function called to specify the number of simulation periods, and called again whenever the user changes the number of simulation periods.
runCalled to run or continue running the simulation until the number of periods sent by the last change_periods call have been completed. initialize will be called before the first call to this, and change_periods will have been called one or more times.
stopCalled when the user hits the stop button in the GUI. This should pause the current simulation run loop until run or step are called.
stepCalled when the user wishes to step forward one period then stop.
quitCalled when the user quits the GUI.

Member Function Documentation

§ checkEvents()

void creativity::gui::GUI::checkEvents ( )

Checks whether the GUI has generated any events and, if so, processes them.

If there are no pending events, this returns immediately.

§ error()

void creativity::gui::GUI::error ( std::string  message)

Sends a signal to the GUI thread that an error has occurred.

Takes a string to display in a dialog to the user.

§ initialized()

void creativity::gui::GUI::initialized ( )

Sends a signal to the GUI thread that the simulation setup is complete.

The GUI will disable the various simulation setup options and start/initialize buttons and switch to the visualization tab. The states variable given to the constructor must have been initialized with the initial simulation state: this method sends a new_states signal, to let the GUI thread know that there is a new state.

§ newStates()

void creativity::gui::GUI::newStates ( eris::eris_time_t  switch_to = (eris::eris_time_t) -1)

Signals the GUI thread that one or more states have been completed.

The GUI will record the new number of states. If the user was viewing the most recent state, the GUI will be updated to display the new most recent state, otherwise the GUI remains on the current state.

The optional parameter allows the main thread to instruct the GUI to switch to the given state; if omitted, the GUI switches to the last state if the user was already there before the signal, and otherwise doesn't change the state.

§ progress()

void creativity::gui::GUI::progress ( eris::eris_time_t  t,
eris::eris_time_t  end,
double  speed 
)

Signals the GUI thread of a progress update.

Parameters
tthe current simulation state
endthe simulation stage at which the current run will stop
speedthe speed (in iterations per second)

§ running()

void creativity::gui::GUI::running ( )

Sends a signal to the GUI thread that the simulation has started or resumed running.

§ stopped()

void creativity::gui::GUI::stopped ( bool  more)

Sends a signal to the GUI thread that the simulation has stopped running.

Parameters
moreis true if there are still more simulation periods to run (as specified in the Periods setting).

§ waitEvents()

void creativity::gui::GUI::waitEvents ( )

If the GUI has queued events, processes them.

If there are no queued events, this waits for an event to occur then processes it.

Inheritance diagram for creativity::gui::GUI:
[legend]
Collaboration diagram for creativity::gui::GUI:
[legend]

The documentation for this class was generated from the following file: