Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
DocumentThread.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include <queue>
5#include <mutex>
6#include <stack>
7#include <map>
8
9#include "DataCell.hh"
10#include "tree.hh"
11
12namespace cadabra {
13
14 class ActionBase;
15 class ActionAddCell;
16 class ActionPositionCursor;
17 class ActionRemoveCell;
18 class ActionSetRunStatus;
19 class ActionSplitCell;
20 class ActionInsertText;
21 class ActionCompleteText;
22 class ActionEraseText;
23 class ComputeThread;
24 class GUIBase;
25
38
39
41 public:
43
47
49
53
54 virtual void set_compute_thread(ComputeThread *);
55
60
62
68
69 void queue_action(std::shared_ptr<ActionBase>);
70
72
73 void new_document();
74
78
79 void load_from_string(const std::string&);
80
81 virtual void on_interactive_output(const nlohmann::json& msg);
82
83 virtual void set_progress(const std::string& msg, int cur_step, int total_steps);
84
86 void undo();
87
89 std::pair<DTree::iterator, size_t> find_string(DTree::iterator start_it, size_t start_pos, const std::string& f, bool case_ins) const;
90
91 friend ActionBase;
100
101 class Prefs {
102 public:
103 using ColorMap = std::map<std::string, std::string>;
104 Prefs(bool use_defaults = false);
105 void save();
110 std::map<std::string, ColorMap> colours;
111 std::string git_path;
112 std::string python_path;
115 private:
116 nlohmann::json data;
117 std::string config_path;
118 };
120
123
124 void set_user_details(const std::string& name, const std::string& email, const std::string& affiliation);
125
126 protected:
129
135
137
143
144 std::mutex stack_mutex;
145 typedef std::stack<std::shared_ptr<ActionBase> > ActionStack;
147 std::queue<std::shared_ptr<ActionBase> > pending_actions;
149
152
154 virtual bool on_unhandled_error(const std::exception& err);
155
156
157
159 enum class help_t { algorithm, property, latex, none };
160 bool help_type_and_topic(const std::string& before, const std::string& after,
161 help_t& help_type, std::string& help_topic) const;
162
163 };
164
165 }
websocketpp::client< websocketpp::config::asio_client > client
Definition ComputeThread.cc:15
Base class which talks to the server and sends Action objects back to the DocumentThread.
Definition ComputeThread.hh:36
Definition DocumentThread.hh:101
bool tab_completion
Definition DocumentThread.hh:114
std::map< std::string, ColorMap > colours
Definition DocumentThread.hh:110
Prefs(bool use_defaults=false)
Definition DocumentThread.cc:211
std::map< std::string, std::string > ColorMap
Definition DocumentThread.hh:103
std::string git_path
Definition DocumentThread.hh:111
nlohmann::json data
Definition DocumentThread.hh:116
std::string python_path
Definition DocumentThread.hh:112
bool is_anonymous
Definition DocumentThread.hh:109
std::string config_path
Definition DocumentThread.hh:117
void save()
Definition DocumentThread.cc:289
bool move_into_new_cell
Definition DocumentThread.hh:113
bool highlight
Definition DocumentThread.hh:107
bool is_registered
Definition DocumentThread.hh:108
int font_step
Definition DocumentThread.hh:106
A base class with all the logic to manipulate a Cadabra notebook document.
Definition DocumentThread.hh:40
help_t
Help system.
Definition DocumentThread.hh:159
void queue_action(std::shared_ptr< ActionBase >)
All changes to the document should be made by submitting ActionBase derived objects to the 'queue_act...
Definition DocumentThread.cc:165
virtual void on_interactive_output(const nlohmann::json &msg)
Definition DocumentThread.cc:37
void undo()
One undo step.
Definition DocumentThread.cc:85
ActionStack undo_stack
Definition DocumentThread.hh:146
void load_from_string(const std::string &)
Load a new notebook from a JSON string.
Definition DocumentThread.cc:75
virtual bool on_unhandled_error(const std::exception &err)
Definition DocumentThread.cc:206
virtual void set_compute_thread(ComputeThread *)
Let the notebook know about the ComputeThread so that it can send cells for evaluation.
Definition DocumentThread.cc:47
friend ActionSetRunStatus
Definition DocumentThread.hh:96
friend ActionPositionCursor
Definition DocumentThread.hh:93
friend ActionEraseText
Definition DocumentThread.hh:99
DTree doc
The actual document tree.
Definition DocumentThread.hh:136
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.
Definition DocumentThread.cc:311
friend ActionRemoveCell
Definition DocumentThread.hh:94
std::queue< std::shared_ptr< ActionBase > > pending_actions
Definition DocumentThread.hh:147
std::stack< std::shared_ptr< ActionBase > > ActionStack
Definition DocumentThread.hh:145
GUIBase * gui
Definition DocumentThread.hh:127
virtual void set_progress(const std::string &msg, int cur_step, int total_steps)
Definition DocumentThread.cc:42
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition DocumentThread.hh:144
DocumentThread(GUIBase *)
Definition DocumentThread.cc:24
friend ActionCompleteText
Definition DocumentThread.hh:98
ActionStack redo_stack
Definition DocumentThread.hh:146
void build_visual_representation()
Ensure that the gui has an up-to-date representation of the dtree.
Definition DocumentThread.cc:106
friend ActionBase
Definition DocumentThread.hh:91
void new_document()
Setup an empty new document with a single Python input cell.
Definition DocumentThread.cc:52
friend ActionAddCell
Definition DocumentThread.hh:92
friend ActionSplitCell
Definition DocumentThread.hh:95
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).
Definition DocumentThread.cc:142
DocumentThread(const DocumentThread &)=delete
It is not possible to copy-construct a DocumentThread as it holds on to resources which are not easil...
bool help_type_and_topic(const std::string &before, const std::string &after, help_t &help_type, std::string &help_topic) const
Definition DocumentThread.cc:320
friend ActionInsertText
Definition DocumentThread.hh:97
ComputeThread * compute
Definition DocumentThread.hh:128
void process_action_queue()
Process the action queue.
Definition DocumentThread.cc:172
Prefs prefs
Definition DocumentThread.hh:119
bool disable_stacks
Definition DocumentThread.hh:148
Abstract base class with methods that need to be implemented by any GUI.
Definition GUIBase.hh:16
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
tree< DataCell > DTree
Definition DataCell.hh:108