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  std::string git_path;
105  private:
106  Json::Value data;
107  std::string config_path;
108  };
110 
113 
114  void set_user_details(const std::string& name, const std::string& email, const std::string& affiliation);
115 
116  protected:
119 
125 
127 
133 
134  std::mutex stack_mutex;
135  typedef std::stack<std::shared_ptr<ActionBase> > ActionStack;
137  std::queue<std::shared_ptr<ActionBase> > pending_actions;
139 
142 
143  void process_action_queue();
144 
145 
146 
148  enum class help_t { algorithm, property, latex, none };
149  bool help_type_and_topic(const std::string& before, const std::string& after,
150  help_t& help_type, std::string& help_topic) const;
151 
152  };
153 
154  }
cadabra::DocumentThread::help_t::algorithm
cadabra::DocumentThread::ActionSplitCell
friend ActionSplitCell
Definition: DocumentThread.hh:89
cadabra::DocumentThread::Prefs::config_path
std::string config_path
Definition: DocumentThread.hh:107
cadabra::DocumentThread::ActionBase
friend ActionBase
Definition: DocumentThread.hh:85
cadabra::DocumentThread::undo
void undo()
One undo step.
Definition: DocumentThread.cc:81
cadabra::DocumentThread::ActionStack
std::stack< std::shared_ptr< ActionBase > > ActionStack
Definition: DocumentThread.hh:135
cadabra::ComputeThread
Definition: ComputeThread.hh:35
cadabra::DocumentThread::ActionSetRunStatus
friend ActionSetRunStatus
Definition: DocumentThread.hh:90
cadabra::DocumentThread::load_from_string
void load_from_string(const std::string &)
Load a new notebook from a JSON string.
Definition: DocumentThread.cc:71
cadabra::DocumentThread::Prefs::git_path
std::string git_path
Definition: DocumentThread.hh:104
cadabra::GUIBase
Definition: GUIBase.hh:16
cadabra::DocumentThread::ActionInsertText
friend ActionInsertText
Definition: DocumentThread.hh:91
cadabra::DocumentThread::redo_stack
ActionStack redo_stack
Definition: DocumentThread.hh:136
cadabra::DocumentThread::disable_stacks
bool disable_stacks
Definition: DocumentThread.hh:138
cadabra::DocumentThread::Prefs::font_step
int font_step
Definition: DocumentThread.hh:99
cadabra::DocumentThread::set_user_details
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:229
cadabra::DocumentThread::undo_stack
ActionStack undo_stack
Definition: DocumentThread.hh:136
cadabra::DocumentThread::set_compute_thread
virtual void set_compute_thread(ComputeThread *)
Let the notebook know about the ComputeThread so that it can send cells for evaluation.
Definition: DocumentThread.cc:43
cadabra::DocumentThread::gui
GUIBase * gui
Definition: DocumentThread.hh:117
cadabra::DocumentThread::doc
DTree doc
The actual document tree.
Definition: DocumentThread.hh:126
cadabra::DocumentThread::help_t
help_t
Help system.
Definition: DocumentThread.hh:148
cadabra::DocumentThread::Prefs::colours
std::map< std::string, ColorMap > colours
Definition: DocumentThread.hh:103
cadabra::DocumentThread::help_t::none
cadabra::DocumentThread::help_t::property
cadabra::DocumentThread::prefs
Prefs prefs
Definition: DocumentThread.hh:109
cadabra::DocumentThread::Prefs::ColorMap
std::map< std::string, std::string > ColorMap
Definition: DocumentThread.hh:96
cadabra::DocumentThread::ActionPositionCursor
friend ActionPositionCursor
Definition: DocumentThread.hh:87
cadabra::DocumentThread::queue_action
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:120
snoop::email
const char email[]
Definition: Snoop.hh:163
cadabra::DocumentThread::build_visual_representation
void build_visual_representation()
Ensure that the gui has an up-to-date representation of the dtree.
Definition: DocumentThread.cc:102
cadabra::DocumentThread::Prefs::highlight
bool highlight
Definition: DocumentThread.hh:100
cadabra::DocumentThread::ActionRemoveCell
friend ActionRemoveCell
Definition: DocumentThread.hh:88
cadabra::DocumentThread::help_type_and_topic
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:238
cadabra::DocumentThread::Prefs
Definition: DocumentThread.hh:94
cadabra::DocumentThread::Prefs::is_registered
bool is_registered
Definition: DocumentThread.hh:101
cadabra::DocumentThread::ActionAddCell
friend ActionAddCell
Definition: DocumentThread.hh:86
cadabra::DocumentThread::DocumentThread
DocumentThread(GUIBase *)
Definition: DocumentThread.cc:25
DataCell.hh
cadabra::DocumentThread::help_t::latex
cadabra::DocumentThread::ActionEraseText
friend ActionEraseText
Definition: DocumentThread.hh:92
cadabra::DTree
tree< DataCell > DTree
Definition: DataCell.hh:108
cadabra::DocumentThread
Definition: DocumentThread.hh:39
cadabra::DocumentThread::on_interactive_output
virtual void on_interactive_output(const Json::Value &msg)
Definition: DocumentThread.cc:38
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:80
cadabra::DocumentThread::stack_mutex
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition: DocumentThread.hh:134
cadabra::DocumentThread::Prefs::data
Json::Value data
Definition: DocumentThread.hh:106
cadabra::DocumentThread::Prefs::save
void save()
Definition: DocumentThread.cc:210
cadabra::DocumentThread::new_document
void new_document()
Setup an empty new document with a single Python input cell.
Definition: DocumentThread.cc:48
cadabra::DocumentThread::pending_actions
std::queue< std::shared_ptr< ActionBase > > pending_actions
Definition: DocumentThread.hh:137
cadabra::DocumentThread::Prefs::is_anonymous
bool is_anonymous
Definition: DocumentThread.hh:102
cadabra::DocumentThread::process_action_queue
void process_action_queue()
Process the action queue.
Definition: DocumentThread.cc:127
cadabra::DocumentThread::compute
ComputeThread * compute
Definition: DocumentThread.hh:118
cadabra::DocumentThread::Prefs::Prefs
Prefs(bool use_defaults=false)
Definition: DocumentThread.cc:157