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 ActionCompleteText;
22  class ActionEraseText;
23  class ComputeThread;
24  class GUIBase;
25 
38 
39 
41  public:
43 
47 
48  DocumentThread(const DocumentThread&)=delete;
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;
92  friend ActionAddCell;
100 
101  class Prefs {
102  public:
103  using ColorMap = std::map<std::string, std::string>;
104  Prefs(bool use_defaults = false);
105  void save();
107  bool highlight;
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 
153  void process_action_queue();
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  }
cadabra::DocumentThread::ActionEraseText
friend ActionEraseText
Definition: DocumentThread.hh:99
cadabra::DocumentThread::Prefs::is_registered
bool is_registered
Definition: DocumentThread.hh:108
cadabra::DocumentThread::undo_stack
ActionStack undo_stack
Definition: DocumentThread.hh:146
cadabra::DocumentThread::pending_actions
std::queue< std::shared_ptr< ActionBase > > pending_actions
Definition: DocumentThread.hh:147
cadabra::DocumentThread::help_t
help_t
Help system.
Definition: DocumentThread.hh:159
cadabra::DocumentThread::help_t::algorithm
@ algorithm
cadabra::DocumentThread::Prefs::tab_completion
bool tab_completion
Definition: DocumentThread.hh:114
cadabra::DocumentThread::ActionRemoveCell
friend ActionRemoveCell
Definition: DocumentThread.hh:94
cadabra::DocumentThread::gui
GUIBase * gui
Definition: DocumentThread.hh:127
cadabra::DocumentThread::process_action_queue
void process_action_queue()
Process the action queue.
Definition: DocumentThread.cc:172
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:311
cadabra::DocumentThread::on_unhandled_error
virtual bool on_unhandled_error(const std::exception &err)
Definition: DocumentThread.cc:206
cadabra::DocumentThread::undo
void undo()
One undo step.
Definition: DocumentThread.cc:85
cadabra::DocumentThread::Prefs::Prefs
Prefs(bool use_defaults=false)
Definition: DocumentThread.cc:211
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:47
cadabra::DocumentThread::help_t::latex
@ latex
cadabra::DocumentThread::Prefs::config_path
std::string config_path
Definition: DocumentThread.hh:117
cadabra::DocumentThread::ActionInsertText
friend ActionInsertText
Definition: DocumentThread.hh:97
cadabra::DocumentThread::Prefs::python_path
std::string python_path
Definition: DocumentThread.hh:112
cadabra::DocumentThread::new_document
void new_document()
Setup an empty new document with a single Python input cell.
Definition: DocumentThread.cc:52
cadabra::DocumentThread::Prefs::font_step
int font_step
Definition: DocumentThread.hh:106
nevaluate.f
f
Definition: nevaluate.py:14
cadabra::DocumentThread::Prefs::git_path
std::string git_path
Definition: DocumentThread.hh:111
cadabra::DocumentThread::ActionSplitCell
friend ActionSplitCell
Definition: DocumentThread.hh:95
cadabra::DocumentThread::stack_mutex
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition: DocumentThread.hh:144
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:320
cadabra::DocumentThread::Prefs
Definition: DocumentThread.hh:101
snoop::email
const char email[]
Definition: Snoop.hh:340
cadabra::DocumentThread::Prefs::ColorMap
std::map< std::string, std::string > ColorMap
Definition: DocumentThread.hh:103
cadabra::DocumentThread::redo_stack
ActionStack redo_stack
Definition: DocumentThread.hh:146
cadabra::ComputeThread
Definition: ComputeThread.hh:36
cadabra::DocumentThread::Prefs::colours
std::map< std::string, ColorMap > colours
Definition: DocumentThread.hh:110
cadabra::DocumentThread::load_from_string
void load_from_string(const std::string &)
Load a new notebook from a JSON string.
Definition: DocumentThread.cc:75
cadabra::DocumentThread::ActionSetRunStatus
friend ActionSetRunStatus
Definition: DocumentThread.hh:96
cadabra::DocumentThread::ActionStack
std::stack< std::shared_ptr< ActionBase > > ActionStack
Definition: DocumentThread.hh:145
cadabra::GUIBase
Definition: GUIBase.hh:16
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:165
cadabra::DocumentThread::ActionCompleteText
friend ActionCompleteText
Definition: DocumentThread.hh:98
cadabra::DTree
tree< DataCell > DTree
Definition: DataCell.hh:108
cadabra::DocumentThread::Prefs::data
nlohmann::json data
Definition: DocumentThread.hh:116
cadabra::DocumentThread::disable_stacks
bool disable_stacks
Definition: DocumentThread.hh:148
cadabra::DocumentThread::compute
ComputeThread * compute
Definition: DocumentThread.hh:128
cadabra::DocumentThread::Prefs::move_into_new_cell
bool move_into_new_cell
Definition: DocumentThread.hh:113
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
cadabra::DocumentThread::doc
DTree doc
The actual document tree.
Definition: DocumentThread.hh:136
cadabra::DocumentThread::ActionAddCell
friend ActionAddCell
Definition: DocumentThread.hh:92
cadabra::DocumentThread::prefs
Prefs prefs
Definition: DocumentThread.hh:119
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:106
cadabra::DocumentThread::on_interactive_output
virtual void on_interactive_output(const nlohmann::json &msg)
Definition: DocumentThread.cc:37
DataCell.hh
cadabra::DocumentThread::DocumentThread
DocumentThread(GUIBase *)
Definition: DocumentThread.cc:24
cadabra::DocumentThread::Prefs::save
void save()
Definition: DocumentThread.cc:289
cadabra::DocumentThread::ActionPositionCursor
friend ActionPositionCursor
Definition: DocumentThread.hh:93
cadabra::DocumentThread::Prefs::highlight
bool highlight
Definition: DocumentThread.hh:107
cadabra::DocumentThread::help_t::property
@ property
cadabra::DocumentThread
Definition: DocumentThread.hh:40
cadabra::DocumentThread::find_string
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
cadabra::DocumentThread::set_progress
virtual void set_progress(const std::string &msg, int cur_step, int total_steps)
Definition: DocumentThread.cc:42
cadabra::DocumentThread::ActionBase
friend ActionBase
Definition: DocumentThread.hh:91
cadabra::DocumentThread::Prefs::is_anonymous
bool is_anonymous
Definition: DocumentThread.hh:109
cadabra::DocumentThread::help_t::none
@ none