KoMo2  1.0.0
A modern ARM emulator GUI.
KoMo2Model.cpp
Go to the documentation of this file.
1 
10 #include "KoMo2Model.h"
11 #include <atkmm/action.h>
12 #include <glibmm.h>
13 #include <gtkmm/filechooserdialog.h>
14 #include <iostream>
15 #include "../views/MainWindowView.h"
16 
29  const std::string argv0,
30  const std::string manual,
31  const int refreshRate)
32  : Model(this),
33  mainWindow(mainWindow),
34  absolutePathToProjectRoot(argv0),
35  compileLoadModel(mainWindow->getCompileLoadView(), this),
36  controlsModel(mainWindow->getControlsView(), manual, this),
37  registersModel(mainWindow->getRegistersView(), this),
38  terminalModel(mainWindow->getTerminalView(), this),
39  disassemblyModel(mainWindow->getDisassemblyView(), this),
40  refreshRate(refreshRate) {
41  // Updates the main window to have a pointer to its model, sets its CSS.
42  getMainWindow()->setModel(this);
44 
45  // Sets key down events to fire on this handleKeyPress method
46  getMainWindow()->signal_key_press_event().connect(
47  sigc::mem_fun(*this, &Model::handleKeyPress), false);
48 
49  changeJimulatorState(JimulatorState::UNLOADED);
50 }
51 
57  // Check the state of the board first
58  switch (Jimulator::checkBoardState()) {
59  case ClientState::FINISHED:
60  getParent()->changeJimulatorState(JimulatorState::UNLOADED);
61  break;
62  case ClientState::BREAKPOINT:
63  getParent()->changeJimulatorState(JimulatorState::PAUSED);
64  break;
65  default:
66  break;
67  }
68 
69  // Updates registers
73 
74  // Returns true if this function should continue looping (i.e. is running)
75  return getJimulatorState() == JimulatorState::RUNNING;
76 }
77 
84 const bool KoMo2Model::handleKeyPress(const GdkEventKey* const e) {
85  return getTerminalModel()->handleKeyPress(e) ||
90 }
91 
98  // No state change, do nothing
99  if (getJimulatorState() == newState) {
100  return;
101  }
102 
103  // Update the overall state of Jimulator State
104  setJimulatorState(newState);
105 
106  // Handles refreshing the views
107  switch (newState) {
108  case JimulatorState::RUNNING:
109  Glib::signal_timeout().connect(
110  sigc::mem_fun(this, &KoMo2Model::refreshViews), refreshRate);
111  break;
112  case JimulatorState::LOADED:
113  case JimulatorState::UNLOADED:
114  refreshViews();
115  break;
116  default:
117  break;
118  }
119 
120  // Change the state of each child model
126 }
127 
128 // !!!!!!!!!!!!!!!!!!!!!!!
129 // ! Getters and setters !
130 // !!!!!!!!!!!!!!!!!!!!!!!
131 
137  return mainWindow;
138 }
144  return &compileLoadModel;
145 }
151  return &controlsModel;
152 }
158  return &registersModel;
159 }
165  return &disassemblyModel;
166 }
172  return &terminalModel;
173 }
178 const std::string KoMo2Model::getAbsolutePathToProjectRoot() const {
180 }
The class definition of the ControlsModel class, a data model which encapsulates all state...
Definition: ControlsModel.h:21
void refreshViews()
Handles updating this particular view. Reads register values from Jimulator, sets the label values of...
The declaration of the DisassemblyModel class.
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles a key press event pertaining to this model.
KoMo2Model(MainWindowView *const mainWindow, const std::string argv0, const std::string manual, const int refreshRate)
Construct a new KoMo2Model - this constructor initialises the mainWindow pointer, as well as the abso...
Definition: KoMo2Model.cpp:28
Represents any data or functions related to the information, or manipulation of the information...
Definition: TerminalModel.h:19
DisassemblyModel *const getDisassemblyModel()
Gets the disassemblyModel member variable.
Definition: KoMo2Model.cpp:164
TerminalModel terminalModel
The data model associated with the terminal view. Represented by the input box and text view at the b...
Definition: KoMo2Model.h:89
CompileLoadModel *const getCompileLoadModel()
Gets the compileLoadModel member variable.
Definition: KoMo2Model.cpp:143
TerminalModel *const getTerminalModel()
Gets the terminalModel member variable.
Definition: KoMo2Model.cpp:171
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
const std::string getAbsolutePathToProjectRoot() const
Gets the absolutePathToProjectRoot member variable.
Definition: KoMo2Model.cpp:178
std::string manual
Manual information read from variables.json is stored here.
Definition: main.cpp:71
virtual void changeJimulatorState(const JimulatorState newState) override
Handles the Jimulator state change for this model. For each value of newState, it will update the sta...
ControlsModel *const getControlsModel()
Gets the controlsModel member variable.
Definition: KoMo2Model.cpp:150
virtual void changeJimulatorState(const JimulatorState newState) override
Handles changes in the Jimulator state.
KoMo2Model *const getParent() const
Returns the parent pointer.
Definition: Model.cpp:67
const unsigned int refreshRate
Defines how often the the refreshViews function should be called when KoMo2 is in the JimulatorState:...
Definition: KoMo2Model.h:101
JimulatorState getJimulatorState() const
Return the jimulatorState member object.
Definition: Model.cpp:75
RegistersModel registersModel
The data model for the registers view. Represented by the table of values on the left hand side of th...
Definition: KoMo2Model.h:83
const std::string readJimulator() const
Reads for any data from Jimulator.
void setModel(KoMo2Model *const val)
Sets the model member variable.
JimulatorState
Describe the 5 states of Jimulator.
Definition: Model.h:19
ControlsModel controlsModel
The data model for the controls and status functionality of the program, represented by the series of...
Definition: KoMo2Model.h:77
RegistersModel *const getRegistersModel()
Gets the RegistersModel member variable.
Definition: KoMo2Model.cpp:157
MainWindowView *const getMainWindow() const
Gets the mainWindow member variable.
Definition: KoMo2Model.cpp:136
The class definition of the main window of the program. This main window is the mater view of the pro...
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles a change in JimulatorState for this model.
void appendTextToTextView(std::string text)
Appends a string to the current text view of the terminal, and scroll to the bottom of the terminal...
void setJimulatorState(const JimulatorState val)
set the JimulatorState member object.
Definition: Model.cpp:83
A file containing the definition of the KoMo2Model class.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles the internal state of Jimulator being changed.
The superclass for all other Model classes. Uses a pure virtual function, so is abastract. Keeps KoMo2Model as a friend so it alone can call setJimulatorState. This class provides basic data that are needed by all other.
Definition: Model.h:35
const std::string absolutePathToProjectRoot
The absolute path to the project root directory.
Definition: KoMo2Model.h:63
void refreshViews()
Refreshes the values in the views to display the new values fetched from Jimulator.
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
virtual const bool handleKeyPress(const GdkEventKey *const e)=0
Handles key presses for each model.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles changes of Jimulator state.
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Passes the key press event off to other child models.
Definition: KoMo2Model.cpp:84
DisassemblyModel disassemblyModel
The data model associated with the disassembly view. Represents the rows of memory values that take u...
Definition: KoMo2Model.h:95
the class definition of the compileLoadModel class, a data model which encapsulates any statefullness...
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles a key press event for this model.
Stores data and functions relating to the tracking and manipulation of data within the RegistersView ...
virtual void changeJimulatorState(const JimulatorState newState) override
Changes the Jimulator state and calls each child models own changeJimulatorState function.
Definition: KoMo2Model.cpp:97
const ClientState checkBoardState()
Check the state of the board - logs what it is doing.
Definition: kcmd.cpp:422
void setStyling()
Sets the style attributes for the views - namely any icons and CSS.
CompileLoadModel compileLoadModel
The data model for the compile and load functionality of the program, represented by the browse and c...
Definition: KoMo2Model.h:70
const bool refreshViews()
Refreshes the views. May be called on a looping timer.
Definition: KoMo2Model.cpp:56
MainWindowView *const mainWindow
A pointer to the main window view.
Definition: KoMo2Model.h:58