Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | List of all members
cadabra::DocumentThread Class Reference

Description

A base class with all the logic to manipulate a Cadabra notebook document.

Relies on the various objects derived from ActionBase in order to get actual work done. All methods here will always run on the GUI thread.In order to implement a GUI, derive from both DocumentThread and GUIBase and then implement the virtual functions of the latter (those implement basic insertion/removal of notebook cells; the logic to figure out which ones and to implement the undo/redo stack is all in the GUI-agnostic DocumentThread).

#include <DocumentThread.hh>

Inheritance diagram for cadabra::DocumentThread:
cadabra::NotebookWindow

Public Member Functions

 DocumentThread (GUIBase *)
 
 DocumentThread (const DocumentThread &)=delete
 It is not possible to copy-construct a DocumentThread as it holds on to resources which are not easily copied (such as GUI elements). More...
 
void set_compute_thread (ComputeThread *)
 Let the notebook know about the ComputeThread so that it can send cells for evaluation. More...
 
void build_visual_representation ()
 Ensure that the gui has an up-to-date representation of the dtree. More...
 
void queue_action (std::shared_ptr< ActionBase >)
 All changes to the document should be made by submitting ActionBase derived objects to the 'queue_action' function, so that an undo stack can be kept. More...
 
void new_document ()
 Setup an empty new document with a single Python input cell. More...
 
void load_from_string (const std::string &)
 Load a new notebook from a JSON string. More...
 
void undo ()
 One undo step. More...
 
bool is_registered () const
 Determine if a user has been registered with the Cadabra log server. More...
 
void set_user_details (const std::string &name, const std::string &email, const std::string &affiliation)
 Set user details which will be sent to the Cadabra log server. More...
 

Public Attributes

friend ActionBase
 
friend ActionAddCell
 
friend ActionPositionCursor
 
friend ActionRemoveCell
 
friend ActionSplitCell
 
friend ActionSetRunStatus
 
friend ActionInsertText
 
friend ActionEraseText
 

Protected Types

enum  help_t { help_t::algorithm, help_t::property, help_t::latex, help_t::none }
 Help system. More...
 
typedef std::stack
< std::shared_ptr< ActionBase > > 
ActionStack
 

Protected Member Functions

void process_action_queue ()
 Process the action queue. More...
 
bool help_type_and_topic (const std::string &before, const std::string &after, help_t &help_type, std::string &help_topic) const
 

Protected Attributes

GUIBasegui
 
ComputeThreadcompute
 
DTree doc
 The actual document tree. More...
 
std::mutex stack_mutex
 The action undo/redo/todo stacks and logic to execute. More...
 
ActionStack undo_stack
 
ActionStack redo_stack
 
std::queue< std::shared_ptr
< ActionBase > > 
pending_actions
 
bool disable_stacks
 
bool registered
 Configuration options read from ~/.config/cadabra.conf. More...
 

Member Typedef Documentation

typedef std::stack<std::shared_ptr<ActionBase> > cadabra::DocumentThread::ActionStack
protected

Member Enumeration Documentation

enum cadabra::DocumentThread::help_t
strongprotected

Help system.

Enumerator
algorithm 
property 
latex 
none 

Constructor & Destructor Documentation

DocumentThread::DocumentThread ( GUIBase g)
cadabra::DocumentThread::DocumentThread ( const DocumentThread )
delete

It is not possible to copy-construct a DocumentThread as it holds on to resources which are not easily copied (such as GUI elements).

Member Function Documentation

void DocumentThread::build_visual_representation ( )

Ensure that the gui has an up-to-date representation of the dtree.

Traverses the entire tree so is expensive to run and should only be used when loading new documents or creating a new canvas view.

bool DocumentThread::help_type_and_topic ( const std::string &  before,
const std::string &  after,
help_t help_type,
std::string &  help_topic 
) const
protected
bool DocumentThread::is_registered ( ) const

Determine if a user has been registered with the Cadabra log server.

void DocumentThread::load_from_string ( const std::string &  json)

Load a new notebook from a JSON string.

Should only be called from the GUI thread. Will cancel any pending operations on the existing notebook (if present) first.

void DocumentThread::new_document ( )

Setup an empty new document with a single Python input cell.

void DocumentThread::process_action_queue ( )
protected

Process the action queue.

It is allowed to call queue_action() above while this is running. So a running action can add more actions.

void DocumentThread::queue_action ( std::shared_ptr< ActionBase ab)

All changes to the document should be made by submitting ActionBase derived objects to the 'queue_action' function, so that an undo stack can be kept.

They are then processed by calling the 'process_action_queue' method (only available from this thread).

void DocumentThread::set_compute_thread ( ComputeThread cl)

Let the notebook know about the ComputeThread so that it can send cells for evaluation.

Notebook does NOT own this pointer.

void DocumentThread::set_user_details ( const std::string &  name,
const std::string &  email,
const std::string &  affiliation 
)

Set user details which will be sent to the Cadabra log server.

void DocumentThread::undo ( )

One undo step.

Member Data Documentation

friend cadabra::DocumentThread::ActionAddCell
friend cadabra::DocumentThread::ActionBase
friend cadabra::DocumentThread::ActionEraseText
friend cadabra::DocumentThread::ActionInsertText
friend cadabra::DocumentThread::ActionPositionCursor
friend cadabra::DocumentThread::ActionRemoveCell
friend cadabra::DocumentThread::ActionSetRunStatus
friend cadabra::DocumentThread::ActionSplitCell
ComputeThread* cadabra::DocumentThread::compute
protected
bool cadabra::DocumentThread::disable_stacks
protected
DTree cadabra::DocumentThread::doc
protected

The actual document tree.

This object is only modified on the GUI thread, either directly by code in DocumentThread, or by code in the various objects derived from ActionBase. In particular, ComputeThread cannot access this tree directly.

GUIBase* cadabra::DocumentThread::gui
protected
std::queue<std::shared_ptr<ActionBase> > cadabra::DocumentThread::pending_actions
protected
ActionStack cadabra::DocumentThread::redo_stack
protected
bool cadabra::DocumentThread::registered
protected

Configuration options read from ~/.config/cadabra.conf.

std::mutex cadabra::DocumentThread::stack_mutex
protected

The action undo/redo/todo stacks and logic to execute.

them. These stacks can be accessed from both the DocumentThread as well as the ComputeThread (the latter does it through the DocumentThread::queue_action method), so they need a mutex to access them.

ActionStack cadabra::DocumentThread::undo_stack
protected

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