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 Json::Value& msg);
82 
84  void undo();
85 
87  std::pair<DTree::iterator, size_t> find_string(DTree::iterator start_it, size_t start_pos, const std::string& f, bool case_ins) const;
88 
89  friend ActionBase;
90  friend ActionAddCell;
98 
99  class Prefs {
100  public:
101  using ColorMap = std::map<std::string, std::string>;
102  Prefs(bool use_defaults = false);
103  void save();
105  bool highlight;
108  std::map<std::string, ColorMap> colours;
109  std::string git_path;
110  std::string python_path;
113  private:
114  Json::Value data;
115  std::string config_path;
116  };
118 
121 
122  void set_user_details(const std::string& name, const std::string& email, const std::string& affiliation);
123 
124  protected:
127 
133 
135 
141 
142  std::mutex stack_mutex;
143  typedef std::stack<std::shared_ptr<ActionBase> > ActionStack;
145  std::queue<std::shared_ptr<ActionBase> > pending_actions;
147 
150 
151  void process_action_queue();
152 
153 
154 
156  enum class help_t { algorithm, property, latex, none };
157  bool help_type_and_topic(const std::string& before, const std::string& after,
158  help_t& help_type, std::string& help_topic) const;
159 
160  };
161 
162  }
cadabra::DocumentThread::help_t::algorithm
cadabra::DocumentThread::ActionSplitCell
friend ActionSplitCell
Definition: DocumentThread.hh:93
cadabra::DocumentThread::Prefs::config_path
std::string config_path
Definition: DocumentThread.hh:115
cadabra::DocumentThread::ActionBase
friend ActionBase
Definition: DocumentThread.hh:89
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:143
cadabra::ComputeThread
Definition: ComputeThread.hh:35
cadabra::DocumentThread::ActionSetRunStatus
friend ActionSetRunStatus
Definition: DocumentThread.hh:94
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:109
cadabra::GUIBase
Definition: GUIBase.hh:16
cadabra::DocumentThread::ActionInsertText
friend ActionInsertText
Definition: DocumentThread.hh:95
cadabra::DocumentThread::redo_stack
ActionStack redo_stack
Definition: DocumentThread.hh:144
cadabra::DocumentThread::disable_stacks
bool disable_stacks
Definition: DocumentThread.hh:146
cadabra::DocumentThread::Prefs::font_step
int font_step
Definition: DocumentThread.hh:104
cadabra::DocumentThread::Prefs::tab_completion
bool tab_completion
Definition: DocumentThread.hh:112
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:277
cadabra::DocumentThread::undo_stack
ActionStack undo_stack
Definition: DocumentThread.hh:144
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::Prefs::move_into_new_cell
bool move_into_new_cell
Definition: DocumentThread.hh:111
cadabra::DocumentThread::gui
GUIBase * gui
Definition: DocumentThread.hh:125
cadabra::DocumentThread::doc
DTree doc
The actual document tree.
Definition: DocumentThread.hh:134
cadabra::DocumentThread::help_t
help_t
Help system.
Definition: DocumentThread.hh:156
cadabra::DocumentThread::Prefs::colours
std::map< std::string, ColorMap > colours
Definition: DocumentThread.hh:108
cadabra::DocumentThread::help_t::none
cadabra::DocumentThread::help_t::property
cadabra::DocumentThread::prefs
Prefs prefs
Definition: DocumentThread.hh:117
cadabra::DocumentThread::Prefs::ColorMap
std::map< std::string, std::string > ColorMap
Definition: DocumentThread.hh:101
cadabra::DocumentThread::ActionPositionCursor
friend ActionPositionCursor
Definition: DocumentThread.hh:91
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:161
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:105
cadabra::DocumentThread::ActionRemoveCell
friend ActionRemoveCell
Definition: DocumentThread.hh:92
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:286
cadabra::DocumentThread::Prefs
Definition: DocumentThread.hh:99
cadabra::DocumentThread::Prefs::is_registered
bool is_registered
Definition: DocumentThread.hh:106
cadabra::DocumentThread::ActionAddCell
friend ActionAddCell
Definition: DocumentThread.hh:90
cadabra::DocumentThread::DocumentThread
DocumentThread(GUIBase *)
Definition: DocumentThread.cc:25
DataCell.hh
cadabra::DocumentThread::help_t::latex
cadabra::DocumentThread::ActionEraseText
friend ActionEraseText
Definition: DocumentThread.hh:97
cadabra::DTree
tree< DataCell > DTree
Definition: DataCell.hh:108
cadabra::DocumentThread
Definition: DocumentThread.hh:40
cadabra::DocumentThread::on_interactive_output
virtual void on_interactive_output(const Json::Value &msg)
Definition: DocumentThread.cc:38
cadabra::DocumentThread::Prefs::python_path
std::string python_path
Definition: DocumentThread.hh:110
cadabra::DocumentThread::ActionCompleteText
friend ActionCompleteText
Definition: DocumentThread.hh:96
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:82
cadabra::DocumentThread::stack_mutex
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition: DocumentThread.hh:142
cadabra::DocumentThread::Prefs::data
Json::Value data
Definition: DocumentThread.hh:114
cadabra::DocumentThread::Prefs::save
void save()
Definition: DocumentThread.cc:255
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:145
cadabra::DocumentThread::Prefs::is_anonymous
bool is_anonymous
Definition: DocumentThread.hh:107
cadabra::DocumentThread::process_action_queue
void process_action_queue()
Process the action queue.
Definition: DocumentThread.cc:168
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:138
cadabra::DocumentThread::compute
ComputeThread * compute
Definition: DocumentThread.hh:126
cadabra::DocumentThread::Prefs::Prefs
Prefs(bool use_defaults=false)
Definition: DocumentThread.cc:198