Cadabra
Computer algebra system for field theory problems
|
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>
Classes | |
class | Prefs |
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... | |
virtual 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... | |
virtual void | on_interactive_output (const nlohmann::json &msg) |
virtual void | set_progress (const std::string &msg, int cur_step, int total_steps) |
void | undo () |
One undo step. More... | |
void | redo () |
One redo step. More... | |
std::pair< DTree::iterator, size_t > | find_string (DTree::iterator start_it, size_t start_pos, const std::string &f, bool case_ins) const |
Find string, return match, or a (doc.end(), std::string::npos). 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 | ActionCompleteText |
friend | ActionEraseText |
Prefs | prefs |
std::thread::id | main_thread_id |
For debugging purposes we store the main thread idea here (the main Cadabra class sets it). More... | |
Protected Types | |
enum class | help_t { algorithm , property , latex , none } |
Help system. More... | |
typedef std::stack< std::shared_ptr< ActionBase > > | ActionStack |
Protected Member Functions | |
void | process_action_queue () |
Process the action queue. More... | |
virtual bool | on_unhandled_error (const std::exception &err) |
bool | help_type_and_topic (const std::string &before, const std::string &after, help_t &help_type, std::string &help_topic) const |
Protected Attributes | |
GUIBase * | gui |
ComputeThread * | compute |
DTree | doc |
The actual document tree. More... | |
std::mutex | stack_mutex |
The action undo/redo/todo stacks and logic to execute them. More... | |
ActionStack | undo_stack |
ActionStack | redo_stack |
std::queue< std::shared_ptr< ActionBase > > | pending_actions |
bool | disable_stacks |
|
protected |
|
strongprotected |
DocumentThread::DocumentThread | ( | GUIBase * | g | ) |
|
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).
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.
std::pair< DTree::iterator, size_t > DocumentThread::find_string | ( | DTree::iterator | start_it, |
size_t | start_pos, | ||
const std::string & | f, | ||
bool | case_ins | ||
) | const |
Find string, return match, or a (doc.end(), std::string::npos).
|
protected |
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.
|
virtual |
Reimplemented in cadabra::NotebookWindow.
|
protectedvirtual |
Reimplemented in cadabra::NotebookWindow.
|
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. Needs to be called on the GUI thread!
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::redo | ( | ) |
One redo step.
|
virtual |
Let the notebook know about the ComputeThread so that it can send cells for evaluation.
Notebook does NOT own this pointer.
Reimplemented in cadabra::NotebookWindow.
|
virtual |
Reimplemented in cadabra::NotebookWindow.
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.
friend cadabra::DocumentThread::ActionAddCell |
friend cadabra::DocumentThread::ActionBase |
friend cadabra::DocumentThread::ActionCompleteText |
friend cadabra::DocumentThread::ActionEraseText |
friend cadabra::DocumentThread::ActionInsertText |
friend cadabra::DocumentThread::ActionPositionCursor |
friend cadabra::DocumentThread::ActionRemoveCell |
friend cadabra::DocumentThread::ActionSetRunStatus |
friend cadabra::DocumentThread::ActionSplitCell |
|
protected |
|
protected |
|
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.
|
protected |
std::thread::id cadabra::DocumentThread::main_thread_id |
For debugging purposes we store the main thread idea here (the main Cadabra class sets it).
|
protected |
Prefs cadabra::DocumentThread::prefs |
|
protected |
|
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.
|
protected |