Cadabra
Computer algebra system for field theory problems
Actions.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "DataCell.hh"
5 #include "DocumentThread.hh"
6 
7 #include <memory>
8 
9 namespace cadabra {
10 
11  class DocumentThread;
12  class GUIBase;
13 
30 
31 
32  class ActionBase {
33  public:
35 
40 
41  virtual void execute(DocumentThread&, GUIBase&);
42 
44 
45  virtual void revert(DocumentThread&, GUIBase&)=0;
46 
48  virtual bool undoable() const;
49 
51  protected:
52  DTree::iterator ref;
53  };
54 
58 
59  class ActionAddCell : public ActionBase {
60  public:
61  enum class Position { before, after, child };
62 
64  virtual ~ActionAddCell() {};
65 
66  virtual void execute(DocumentThread&, GUIBase&) override;
67  virtual void revert(DocumentThread&, GUIBase&) override;
68 
69  private:
70  // Keep track of the location where this cell is inserted into
71  // the notebook.
72 
74  DTree::iterator newref;
76  int child_num;
77  };
78 
79 
84 
86  public:
87  enum class Position { in, next, previous };
88 
90  virtual ~ActionPositionCursor() {};
91 
92  virtual void execute(DocumentThread&, GUIBase&) override;
93  virtual void revert(DocumentThread&, GUIBase&) override;
94 
95  private:
97  DTree::iterator newref;
99  };
100 
104 
106  public:
107  ActionSetRunStatus(DataCell::id_t ref_id_, bool running);
108  virtual ~ActionSetRunStatus() {};
109 
110  virtual void execute(DocumentThread&, GUIBase&) override;
111  virtual void revert(DocumentThread&, GUIBase&) override;
112 
113  virtual bool undoable() const override;
114  private:
115  DTree::iterator this_cell;
117  };
118 
119 
123 
124  class ActionRemoveCell : public ActionBase {
125  public:
127  virtual ~ActionRemoveCell();
128 
129  virtual void execute(DocumentThread&, GUIBase&) override;
130  virtual void revert(DocumentThread&, GUIBase&) override;
131 
132  private:
133  // Keep track of the location where this cell (and its child
134  // cells) was in the notebook. We keep a reference to the
135  // parent cell and the index of the current cell as child of
136  // that parent.
137 
139  DTree::iterator reference_parent_cell;
141  };
142 
146 
147  class ActionSplitCell : public ActionBase {
148  public:
150  virtual ~ActionSplitCell();
151 
152  virtual void execute(DocumentThread&, GUIBase&) override;
153  virtual void revert(DocumentThread&, GUIBase&) override;
154 
155  private:
156  DTree::iterator newref; // the newly created cell
157  };
158 
159 
168 
169  class ActionInsertText : public ActionBase {
170  public:
171  ActionInsertText(DataCell::id_t ref_id, int pos, const std::string&);
172  virtual ~ActionInsertText() {};
173 
174  virtual void execute(DocumentThread&, GUIBase&) override;
175  virtual void revert(DocumentThread&, GUIBase&) override;
176 
177  private:
178  DTree::iterator this_cell;
180  std::string text;
181  };
182 
190 
192  public:
193  ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string&, int alternative);
194  virtual ~ActionCompleteText() {};
195 
196  virtual void execute(DocumentThread&, GUIBase&) override;
197  virtual void revert(DocumentThread&, GUIBase&) override;
198 
199  int length() const;
200  int alternative() const;
201 
202  private:
203  DTree::iterator this_cell;
205  std::string text;
206  int alternative_; // in case there is more than one completion alternative
207  };
208 
217 
218  class ActionEraseText : public ActionBase {
219  public:
221  virtual ~ActionEraseText() {};
222 
223  virtual void execute(DocumentThread&, GUIBase&) override;
224  virtual void revert(DocumentThread&, GUIBase&) override;
225 
226  private:
227  DTree::iterator this_cell;
229  std::string removed_text;
230  };
231 
232  }
233 
234 
235 //
236 // class ActionMergeCells
237 
238 
239 
cadabra::ActionCompleteText::this_cell
DTree::iterator this_cell
Definition: Actions.hh:203
cadabra::ActionRemoveCell::reference_child_index
size_t reference_child_index
Definition: Actions.hh:140
cadabra::ActionAddCell::Position
Position
Definition: Actions.hh:61
cadabra::ActionSplitCell::newref
DTree::iterator newref
Definition: Actions.hh:156
cadabra::ActionAddCell::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:42
cadabra::ActionRemoveCell::reference_parent_cell
DTree::iterator reference_parent_cell
Definition: Actions.hh:139
cadabra::ActionAddCell::ActionAddCell
ActionAddCell(DataCell, DataCell::id_t ref_, Position pos_)
Definition: Actions.cc:37
cadabra::ActionSetRunStatus::this_cell
DTree::iterator this_cell
Definition: Actions.hh:115
cadabra::DataCell
Definition: DataCell.hh:27
cadabra::ActionEraseText::ActionEraseText
ActionEraseText(DataCell::id_t ref_id, int, int)
Definition: Actions.cc:306
cadabra::ActionRemoveCell::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:159
cadabra::ActionBase::undoable
virtual bool undoable() const
Can this action be undone?
Definition: Actions.cc:18
cadabra::ActionCompleteText::alternative
int alternative() const
Definition: Actions.cc:301
cadabra::ActionEraseText::~ActionEraseText
virtual ~ActionEraseText()
Definition: Actions.hh:221
cadabra::ActionSetRunStatus
Definition: Actions.hh:105
cadabra::ActionInsertText::ActionInsertText
ActionInsertText(DataCell::id_t ref_id, int pos, const std::string &)
Definition: Actions.cc:254
cadabra::ActionInsertText::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:259
cadabra::ActionRemoveCell::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:172
cadabra::ActionRemoveCell::~ActionRemoveCell
virtual ~ActionRemoveCell()
Definition: Actions.cc:155
cadabra::ActionCompleteText::insert_pos
int insert_pos
Definition: Actions.hh:204
DocumentThread.hh
cadabra::ActionSetRunStatus::was_running_
bool was_running_
Definition: Actions.hh:116
cadabra::ActionCompleteText::ActionCompleteText
ActionCompleteText(DataCell::id_t ref_id, int pos, const std::string &, int alternative)
Definition: Actions.cc:274
cadabra::ActionCompleteText::~ActionCompleteText
virtual ~ActionCompleteText()
Definition: Actions.hh:194
cadabra::ActionPositionCursor::~ActionPositionCursor
virtual ~ActionPositionCursor()
Definition: Actions.hh:90
cadabra::ActionEraseText::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:320
cadabra::ActionSplitCell::ActionSplitCell
ActionSplitCell(DataCell::id_t ref_id)
Definition: Actions.cc:190
cadabra::ActionEraseText::removed_text
std::string removed_text
Definition: Actions.hh:229
cadabra::ActionSplitCell::~ActionSplitCell
virtual ~ActionSplitCell()
Definition: Actions.cc:195
cadabra::ActionSplitCell::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:222
cadabra::ActionCompleteText::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:289
cadabra::ActionCompleteText::length
int length() const
Definition: Actions.cc:296
cadabra::ActionInsertText
Definition: Actions.hh:169
cadabra::ActionRemoveCell::ActionRemoveCell
ActionRemoveCell(DataCell::id_t ref_id_)
Definition: Actions.cc:150
cadabra::ActionPositionCursor::Position
Position
Definition: Actions.hh:87
cadabra::ActionSplitCell
Definition: Actions.hh:147
cadabra::ActionSetRunStatus::ActionSetRunStatus
ActionSetRunStatus(DataCell::id_t ref_id_, bool running)
Definition: Actions.cc:229
cadabra::ActionInsertText::insert_pos
int insert_pos
Definition: Actions.hh:179
cadabra::ActionAddCell::pos
Position pos
Definition: Actions.hh:75
cadabra::ActionInsertText::this_cell
DTree::iterator this_cell
Definition: Actions.hh:178
cadabra::ActionAddCell::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:63
cadabra::ActionPositionCursor::needed_new_cell
bool needed_new_cell
Definition: Actions.hh:96
cadabra::ActionSetRunStatus::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:239
cadabra::ActionCompleteText::text
std::string text
Definition: Actions.hh:205
cadabra::ActionInsertText::text
std::string text
Definition: Actions.hh:180
cadabra::ActionEraseText::to_pos
int to_pos
Definition: Actions.hh:228
cadabra::ActionInsertText::~ActionInsertText
virtual ~ActionInsertText()
Definition: Actions.hh:172
cadabra::ActionPositionCursor::newref
DTree::iterator newref
Definition: Actions.hh:97
cadabra::ActionCompleteText::alternative_
int alternative_
Definition: Actions.hh:206
cadabra::ActionBase::ref_id
DataCell::id_t ref_id
Definition: Actions.hh:50
cadabra::ActionSetRunStatus::~ActionSetRunStatus
virtual ~ActionSetRunStatus()
Definition: Actions.hh:108
cadabra::DataCell::id_t
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition: DataCell.hh:51
cadabra::ActionBase::revert
virtual void revert(DocumentThread &, GUIBase &)=0
Revert the change to the DTree document and the GUI.
cadabra::ActionAddCell::Position::after
@ after
cadabra::ActionRemoveCell::removed_tree
DTree removed_tree
Definition: Actions.hh:138
cadabra::ActionAddCell::newref
DTree::iterator newref
Definition: Actions.hh:74
cadabra::ActionEraseText::from_pos
int from_pos
Definition: Actions.hh:228
cadabra::ActionPositionCursor
Definition: Actions.hh:85
cadabra::GUIBase
Definition: GUIBase.hh:16
cadabra::ActionBase::execute
virtual void execute(DocumentThread &, GUIBase &)
Perform the action.
Definition: Actions.cc:23
cadabra::ActionRemoveCell
Definition: Actions.hh:124
cadabra::ActionBase::ref
DTree::iterator ref
Definition: Actions.hh:52
cadabra::ActionSetRunStatus::undoable
virtual bool undoable() const override
Can this action be undone?
Definition: Actions.cc:234
cadabra::ActionSetRunStatus::new_running_
bool new_running_
Definition: Actions.hh:116
cadabra::DTree
tree< DataCell > DTree
Definition: DataCell.hh:108
cadabra::ActionEraseText::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:311
cadabra::ActionAddCell::child_num
int child_num
Definition: Actions.hh:76
cadabra::ActionPositionCursor::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:80
cadabra::ActionAddCell::Position::child
@ child
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
cadabra::ActionPositionCursor::ActionPositionCursor
ActionPositionCursor(DataCell::id_t ref_id_, Position pos_)
Definition: Actions.cc:75
cadabra::ActionBase::ActionBase
ActionBase(DataCell::id_t ref_id)
Definition: Actions.cc:13
cadabra::ActionEraseText
Definition: Actions.hh:218
cadabra::ActionAddCell
Definition: Actions.hh:59
cadabra::ActionSetRunStatus::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:249
DataCell.hh
cadabra::ActionPositionCursor::Position::in
@ in
cadabra::ActionEraseText::this_cell
DTree::iterator this_cell
Definition: Actions.hh:227
cadabra::ActionPositionCursor::pos
Position pos
Definition: Actions.hh:98
cadabra::ActionAddCell::newcell
DataCell newcell
Definition: Actions.hh:73
cadabra::ActionPositionCursor::Position::previous
@ previous
cadabra::ActionAddCell::Position::before
@ before
cadabra::ActionCompleteText::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:279
cadabra::ActionSplitCell::execute
virtual void execute(DocumentThread &, GUIBase &) override
Perform the action.
Definition: Actions.cc:199
cadabra::ActionPositionCursor::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:140
cadabra::ActionAddCell::~ActionAddCell
virtual ~ActionAddCell()
Definition: Actions.hh:64
cadabra::ActionCompleteText
Definition: Actions.hh:191
cadabra::ActionBase
Definition: Actions.hh:32
cadabra::DocumentThread
Definition: DocumentThread.hh:40
cadabra::ActionInsertText::revert
virtual void revert(DocumentThread &, GUIBase &) override
Revert the change to the DTree document and the GUI.
Definition: Actions.cc:267
cadabra::ActionPositionCursor::Position::next
@ next