Cadabra
Computer algebra system for field theory problems
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 
12 namespace 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 ActionEraseText;
22  class ComputeThread;
23  class GUIBase;
24 
37 
38 
40  public:
42 
46 
47  DocumentThread(const DocumentThread&)=delete;
48 
52 
53  virtual void set_compute_thread(ComputeThread *);
54 
59 
61 
67 
68  void queue_action(std::shared_ptr<ActionBase>);
69 
71 
72  void new_document();
73 
77 
78  void load_from_string(const std::string&);
79 
80  virtual void on_interactive_output(const Json::Value& msg);
81 
83  void undo();
84 
85  friend ActionBase;
86  friend ActionAddCell;
93 
94  class Prefs {
95  public:
96  using ColorMap = std::map<std::string, std::string>;
97  Prefs(bool use_defaults = false);
98  void save();
99  int font_step;
100  bool highlight;
103  std::map<std::string, ColorMap> colours;
104  private:
105  Json::Value data;
106  std::string config_path;
107  };
109 
112 
113  void set_user_details(const std::string& name, const std::string& email, const std::string& affiliation);
114 
115  protected:
118 
124 
126 
132 
133  std::mutex stack_mutex;
134  typedef std::stack<std::shared_ptr<ActionBase> > ActionStack;
136  std::queue<std::shared_ptr<ActionBase> > pending_actions;
138 
141 
142  void process_action_queue();
143 
144 
145 
147  enum class help_t { algorithm, property, latex, none };
148  bool help_type_and_topic(const std::string& before, const std::string& after,
149  help_t& help_type, std::string& help_topic) const;
150 
151  };
152 
153 }
ActionStack undo_stack
Definition: DocumentThread.hh:135
friend ActionInsertText
Definition: DocumentThread.hh:91
ComputeThread * compute
Definition: DocumentThread.hh:117
A base class with all the logic to manipulate a Cadabra notebook document.
Definition: DocumentThread.hh:39
void new_document()
Setup an empty new document with a single Python input cell.
Definition: DocumentThread.cc:44
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition: DocumentThread.hh:133
std::stack< std::shared_ptr< ActionBase > > ActionStack
Definition: DocumentThread.hh:134
virtual void on_interactive_output(const Json::Value &msg)
Definition: DocumentThread.cc:34
friend ActionBase
Definition: DocumentThread.hh:85
bool is_registered
Definition: DocumentThread.hh:101
Json::Value data
Definition: DocumentThread.hh:105
const char email[]
Definition: Snoop.hh:162
bool is_anonymous
Definition: DocumentThread.hh:102
friend ActionSetRunStatus
Definition: DocumentThread.hh:90
friend ActionAddCell
Definition: DocumentThread.hh:86
void save()
Definition: DocumentThread.cc:201
Definition: DocumentThread.hh:94
Prefs prefs
Definition: DocumentThread.hh:108
DocumentThread(GUIBase *)
Definition: DocumentThread.cc:23
Abstract base class with methods that need to be implemented by any GUI.
Definition: GUIBase.hh:16
void queue_action(std::shared_ptr< ActionBase >)
All changes to the document should be made by submitting ActionBase derived objects to the &#39;queue_act...
Definition: DocumentThread.cc:116
std::queue< std::shared_ptr< ActionBase > > pending_actions
Definition: DocumentThread.hh:136
Prefs(bool use_defaults=false)
Definition: DocumentThread.cc:153
friend ActionRemoveCell
Definition: DocumentThread.hh:88
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Algorithm.cc:1030
std::string config_path
Definition: DocumentThread.hh:106
friend ActionEraseText
Definition: DocumentThread.hh:92
void load_from_string(const std::string &)
Load a new notebook from a JSON string.
Definition: DocumentThread.cc:67
friend ActionPositionCursor
Definition: DocumentThread.hh:87
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:219
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:226
void undo()
One undo step.
Definition: DocumentThread.cc:77
virtual void set_compute_thread(ComputeThread *)
Let the notebook know about the ComputeThread so that it can send cells for evaluation.
Definition: DocumentThread.cc:39
tree< DataCell > DTree
Definition: DataCell.hh:107
std::map< std::string, ColorMap > colours
Definition: DocumentThread.hh:103
int font_step
Definition: DocumentThread.hh:99
void process_action_queue()
Process the action queue.
Definition: DocumentThread.cc:123
std::map< std::string, std::string > ColorMap
Definition: DocumentThread.hh:96
bool disable_stacks
Definition: DocumentThread.hh:137
bool highlight
Definition: DocumentThread.hh:100
help_t
Help system.
Definition: DocumentThread.hh:147
DTree doc
The actual document tree.
Definition: DocumentThread.hh:125
Base class which talks to the server and sends Action objects back to the DocumentThread.
Definition: ComputeThread.hh:35
ActionStack redo_stack
Definition: DocumentThread.hh:135
GUIBase * gui
Definition: DocumentThread.hh:116
void build_visual_representation()
Ensure that the gui has an up-to-date representation of the dtree.
Definition: DocumentThread.cc:98
friend ActionSplitCell
Definition: DocumentThread.hh:89