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#include <thread>
9
10#include "DataCell.hh"
11#include "tree.hh"
12
13namespace cadabra {
14
15 class ActionBase;
16 class ActionAddCell;
17 class ActionPositionCursor;
18 class ActionRemoveCell;
19 class ActionSetRunStatus;
20 class ActionSplitCell;
21 class ActionInsertText;
22 class ActionCompleteText;
23 class ActionEraseText;
24 class ComputeThread;
25 class GUIBase;
26
39
40
42 public:
44
48
50
54
55 virtual void set_compute_thread(ComputeThread *);
56
61
63
69
70 void queue_action(std::shared_ptr<ActionBase>);
71
77
78 void run_cells_referencing_variable(std::string variable, double value);
79
81
82 void new_document();
83
87
88 void load_from_string(const std::string&);
89
90 virtual void on_interactive_output(const nlohmann::json& msg);
91
92 virtual void set_progress(const std::string& msg, int cur_step, int total_steps);
93
95 void undo();
96
98 void redo();
99
101 std::pair<DTree::iterator, size_t> find_string(DTree::iterator start_it, size_t start_pos, const std::string& f, bool case_ins) const;
102
112
113 class Prefs {
114 public:
115 using ColorMap = std::map<std::string, std::string>;
116 Prefs(bool use_defaults = false);
117 void save();
122 std::map<std::string, ColorMap> colours;
123 std::string git_path;
124 std::string python_path;
129 private:
130 nlohmann::json data;
131 std::string config_path;
132 };
134
137
138 void set_user_details(const std::string& name, const std::string& email, const std::string& affiliation);
139
142 std::thread::id main_thread_id;
143
144 protected:
147
153
155
161
162 std::mutex stack_mutex;
163 typedef std::stack<std::shared_ptr<ActionBase> > ActionStack;
165 std::queue<std::shared_ptr<ActionBase> > pending_actions;
167
171
173 virtual bool on_unhandled_error(const std::exception& err);
174
175
176
178 enum class help_t { algorithm, property, latex, none };
179 bool help_type_and_topic(const std::string& before, const std::string& after,
180 help_t& help_type, std::string& help_topic) const;
181
182 };
183
184 }
Base class which talks to the server and sends Action objects back to the DocumentThread.
Definition ComputeThread.hh:29
Definition DocumentThread.hh:113
bool tab_completion
Definition DocumentThread.hh:126
std::map< std::string, ColorMap > colours
Definition DocumentThread.hh:122
std::map< std::string, std::string > ColorMap
Definition DocumentThread.hh:115
std::string git_path
Definition DocumentThread.hh:123
bool microtex
Definition DocumentThread.hh:127
nlohmann::json data
Definition DocumentThread.hh:130
std::string python_path
Definition DocumentThread.hh:124
bool auto_close_latex
Definition DocumentThread.hh:128
bool is_anonymous
Definition DocumentThread.hh:121
std::string config_path
Definition DocumentThread.hh:131
void save()
Definition DocumentThread.cc:355
bool move_into_new_cell
Definition DocumentThread.hh:125
bool highlight
Definition DocumentThread.hh:119
bool is_registered
Definition DocumentThread.hh:120
int font_step
Definition DocumentThread.hh:118
A base class with all the logic to manipulate a Cadabra notebook document.
Definition DocumentThread.hh:41
help_t
Help system.
Definition DocumentThread.hh:178
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:189
virtual void on_interactive_output(const nlohmann::json &msg)
Definition DocumentThread.cc:39
std::thread::id main_thread_id
For debugging purposes we store the main thread idea here (the main Cadabra class sets it).
Definition DocumentThread.hh:142
void undo()
One undo step.
Definition DocumentThread.cc:87
ActionStack undo_stack
Definition DocumentThread.hh:164
void load_from_string(const std::string &)
Load a new notebook from a JSON string.
Definition DocumentThread.cc:77
virtual bool on_unhandled_error(const std::exception &err)
Definition DocumentThread.cc:261
virtual void set_compute_thread(ComputeThread *)
Let the notebook know about the ComputeThread so that it can send cells for evaluation.
Definition DocumentThread.cc:49
friend ActionSetRunStatus
Definition DocumentThread.hh:108
void redo()
One redo step.
Definition DocumentThread.cc:109
friend ActionPositionCursor
Definition DocumentThread.hh:105
friend ActionEraseText
Definition DocumentThread.hh:111
DTree doc
The actual document tree.
Definition DocumentThread.hh:154
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:379
void run_cells_referencing_variable(std::string variable, double value)
Run all cells containing references to a given variable.
Definition DocumentThread.cc:195
friend ActionRemoveCell
Definition DocumentThread.hh:106
std::queue< std::shared_ptr< ActionBase > > pending_actions
Definition DocumentThread.hh:165
std::stack< std::shared_ptr< ActionBase > > ActionStack
Definition DocumentThread.hh:163
GUIBase * gui
Definition DocumentThread.hh:145
virtual void set_progress(const std::string &msg, int cur_step, int total_steps)
Definition DocumentThread.cc:44
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition DocumentThread.hh:162
friend ActionCompleteText
Definition DocumentThread.hh:110
ActionStack redo_stack
Definition DocumentThread.hh:164
void build_visual_representation()
Ensure that the gui has an up-to-date representation of the dtree.
Definition DocumentThread.cc:130
friend ActionBase
Definition DocumentThread.hh:103
void new_document()
Setup an empty new document with a single Python input cell.
Definition DocumentThread.cc:54
friend ActionAddCell
Definition DocumentThread.hh:104
friend ActionSplitCell
Definition DocumentThread.hh:107
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:166
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:388
friend ActionInsertText
Definition DocumentThread.hh:109
ComputeThread * compute
Definition DocumentThread.hh:146
void process_action_queue()
Process the action queue.
Definition DocumentThread.cc:225
Prefs prefs
Definition DocumentThread.hh:133
bool disable_stacks
Definition DocumentThread.hh:166
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:116
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1064