00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MAINWINDOW_H
00025 #define MAINWINDOW_H
00026
00027 #include <QMainWindow>
00028 #include <QString>
00029 #include <QMessageBox>
00030 #include <QItemSelection>
00031 #include <QTableView>
00032 #include <QSplitter>
00033 #include <QTextEdit>
00034 #include <QMultiMap>
00035 #include <QTabWidget>
00036
00037 #include "CustomDelegate.h"
00038
00039 #include "../compiler/compiler.h"
00040 #include <fstream>
00041 #include <sstream>
00042 #include "Target.h"
00043
00044 class QLabel;
00045 class QSpinBox;
00046 class QGroupBox;
00047 class QPushButton;
00048 class QListWidget;
00049 class QListWidgetItem;
00050 class QTreeView;
00051 class QTranslator;
00052 class QTextBrowser;
00053
00054 namespace Aseba
00055 {
00058
00059 class TargetVariablesModel;
00060 class TargetFunctionsModel;
00061 class TargetMemoryModel;
00062 class NamedValuesVectorModel;
00063 class AeslEditor;
00064 class AeslHighlighter;
00065 class EventViewer;
00066 class EditorsPlotsTabWidget;
00067 class DraggableListWidget;
00068
00069 class CompilationLogDialog: public QTextEdit
00070 {
00071 Q_OBJECT
00072
00073 public:
00074 CompilationLogDialog(QWidget *parent = 0);
00075 };
00076
00077 class FixedWidthTableView : public QTableView
00078 {
00079 protected:
00080 int col1Width;
00081
00082 public:
00083 FixedWidthTableView();
00084 void setSecondColumnLongestContent(const QString& content);
00085
00086 protected:
00087 virtual void resizeEvent ( QResizeEvent * event );
00088 };
00089
00090 class EditorsPlotsTabWidget: public QTabWidget
00091 {
00092 Q_OBJECT
00093
00094 public:
00095 void addTab(QWidget* widget, const QString& label, bool closable = false);
00096
00097 public slots:
00098 void removeAndDeleteTab(int index = -1);
00099 };
00100
00101 class MainWindow;
00102
00103 class ScriptTab
00104 {
00105 public:
00106 virtual ~ScriptTab() {}
00107
00108 protected:
00109 void createEditor();
00110
00111 friend class MainWindow;
00112 AeslEditor* editor;
00113 AeslHighlighter *highlighter;
00114 };
00115
00116 class AbsentNodeTab : public QWidget, public ScriptTab
00117 {
00118 Q_OBJECT
00119
00120 public:
00121 AbsentNodeTab(const QString& name, const QString& sourceCode);
00122
00123 const QString name;
00124 };
00125
00126 class NodeTab : public QSplitter, public ScriptTab
00127 {
00128 Q_OBJECT
00129
00130 public:
00131 NodeTab(MainWindow* mainWindow, Target *target, const CommonDefinitions *commonDefinitions, int id, QWidget *parent = 0);
00132 ~NodeTab();
00133 unsigned nodeId() const { return id; }
00134
00135 void variablesMemoryChanged(unsigned start, const VariablesDataVector &variables);
00136
00137 signals:
00138 void uploadReadynessChanged(bool);
00139
00140 protected:
00141 void setupWidgets();
00142 void setupConnections();
00143
00144 public slots:
00145 void clearExecutionErrors();
00146
00147 protected slots:
00148 void resetClicked();
00149 void loadClicked();
00150 void runInterruptClicked();
00151 void nextClicked();
00152 void refreshMemoryClicked();
00153
00154 void writeBytecode();
00155 void reboot();
00156
00157 void setVariableValues(unsigned, const VariablesDataVector &);
00158 void insertVariableName(const QModelIndex &);
00159
00160 void editorContentChanged();
00161 void recompile();
00162 void markTargetUnsynced();
00163
00164 void cursorMoved();
00165 void goToError();
00166
00167 void setBreakpoint(unsigned line);
00168 void clearBreakpoint(unsigned line);
00169 void breakpointClearedAll();
00170
00171 void executionPosChanged(unsigned line);
00172 void executionModeChanged(Target::ExecutionMode mode);
00173
00174 void breakpointSetResult(unsigned line, bool success);
00175
00176 private:
00177 void rehighlight();
00178 void reSetBreakpoints();
00179 void updateHidden();
00180
00181
00182 bool setEditorProperty(const QString &property, const QVariant &value, unsigned line, bool removeOld = false);
00183 bool clearEditorProperty(const QString &property, unsigned line);
00184 bool clearEditorProperty(const QString &property);
00185 void switchEditorProperty(const QString &oldProperty, const QString &newProperty);
00186
00187 protected:
00188 unsigned id;
00189 Target *target;
00190
00191 private:
00192 friend class MainWindow;
00193 MainWindow* mainWindow;
00194 QLabel *cursorPosText;
00195 QLabel *compilationResultImage;
00196 QLabel *compilationResultText;
00197
00198 QLabel *executionModeLabel;
00199 QPushButton *loadButton;
00200 QPushButton *resetButton;
00201 QPushButton *runInterruptButton;
00202 QPushButton *nextButton;
00203 QPushButton *refreshMemoryButton;
00204
00205 TargetVariablesModel *vmMemoryModel;
00206 QTreeView *vmMemoryView;
00207
00208 TargetFunctionsModel *vmFunctionsModel;
00209 QTreeView *vmFunctionsView;
00210
00211 DraggableListWidget* vmLocalEvents;
00212
00213 bool rehighlighting;
00214 int errorPos;
00215 bool firstCompilation;
00216 bool showHidden;
00217
00218 Compiler compiler;
00219 BytecodeVector bytecode;
00220 unsigned allocatedVariablesCount;
00221 };
00222
00223 class MainWindow : public QMainWindow
00224 {
00225 Q_OBJECT
00226
00227 public:
00228 MainWindow(QVector<QTranslator*> translators, const QString& commandLineTarget, QWidget *parent = 0);
00229 ~MainWindow();
00230
00231 signals:
00232 void MainWindowClosed();
00233
00234 private slots:
00235 void about();
00236 void newFile();
00237 void openFile(const QString &path = QString());
00238 void openRecentFile();
00239 bool save();
00240 bool saveFile(const QString &previousFileName = QString());
00241 void exportMemoriesContent();
00242 void importMemoriesContent();
00243 void copyAll();
00244 void showHidden(bool show);
00245
00246 void loadAll();
00247 void resetAll();
00248 void runAll();
00249 void pauseAll();
00250 void stopAll();
00251
00252 void clearAllExecutionError();
00253
00254 void uploadReadynessChanged();
00255 void tabChanged(int);
00256 void sendEvent();
00257 void sendEventIf(const QModelIndex &);
00258 void eventContextMenuRequested(const QPoint & pos);
00259 void logEntryDoubleClicked(QListWidgetItem *);
00260 void showCompilationMessages(bool doShown);
00261
00262 void addEventNameClicked();
00263 void removeEventNameClicked();
00264 void eventsDescriptionsSelectionChanged();
00265
00266 void addConstantClicked();
00267 void removeConstantClicked();
00268 void constantsSelectionChanged();
00269
00270 void nodeConnected(unsigned node);
00271 void nodeDisconnected(unsigned node);
00272 void networkDisconnected();
00273
00274 void userEventsDropped(unsigned amount);
00275 void userEvent(unsigned id, const VariablesDataVector &data);
00276 void arrayAccessOutOfBounds(unsigned node, unsigned line, unsigned size, unsigned index);
00277 void divisionByZero(unsigned node, unsigned line);
00278 void eventExecutionKilled(unsigned node, unsigned line);
00279 void nodeSpecificError(unsigned node, unsigned line, const QString& message);
00280
00281 void executionPosChanged(unsigned node, unsigned line);
00282 void executionModeChanged(unsigned node, Target::ExecutionMode mode);
00283 void variablesMemoryEstimatedDirty(unsigned node);
00284
00285 void variablesMemoryChanged(unsigned node, unsigned start, const VariablesDataVector &variables);
00286
00287 void breakpointSetResult(unsigned node, unsigned line, bool success);
00288
00289 void recompileAll();
00290 void writeAllBytecodes();
00291 void rebootAllNodes();
00292
00293 void sourceChanged();
00294 void updateWindowTitle();
00295
00296 void addPluginLinearCameraView();
00297
00298 void showHelpLanguage();
00299 void showHelpStudio();
00300
00301 private:
00302
00303 int getIndexFromId(unsigned node);
00304 NodeTab* getTabFromId(unsigned node);
00305 NodeTab* getTabFromName(const QString& name);
00306 void addErrorEvent(unsigned node, unsigned line, const QString& message);
00307 void clearDocumentSpecificTabs();
00308 bool askUserBeforeDiscarding();
00309
00310
00311 void regenerateOpenRecentMenu();
00312 void updateRecentFiles(const QString& fileName);
00313 void regenerateToolsMenus();
00314 void setupWidgets();
00315 void setupConnections();
00316 void setupMenu();
00317 void hideEvent(QHideEvent * event);
00318 void closeEvent ( QCloseEvent * event );
00319
00320
00321 friend class NodeTab;
00322 EditorsPlotsTabWidget* nodes;
00323 ScriptTab* previousActiveTab;
00324
00325 #ifdef HAVE_QWT
00326
00327
00328 friend class EventViewer;
00329 typedef QMultiMap<unsigned, EventViewer*> EventViewers;
00330 EventViewers eventsViewers;
00331
00332 #endif // HAVE_QWT
00333
00334
00335 QPushButton* addEventNameButton;
00336 QPushButton* removeEventNameButton;
00337 QPushButton* sendEventButton;
00338 QListWidget* logger;
00339 QPushButton* clearLogger;
00340 FixedWidthTableView* eventsDescriptionsView;
00341
00342
00343 QPushButton* addConstantButton;
00344 QPushButton* removeConstantButton;
00345 FixedWidthTableView* constantsView;
00346
00347
00348 NamedValuesVectorModel* eventsDescriptionsModel;
00349 NamedValuesVectorModel* constantsDefinitionsModel;
00350
00351
00352 QAction* loadAllAct;
00353 QAction* resetAllAct;
00354 QAction* runAllAct;
00355 QAction* pauseAllAct;
00356
00357
00358 QMenu *openRecentMenu;
00359
00360
00361 QMenu *writeBytecodeMenu;
00362 QAction *writeAllBytecodesAct;
00363 QMenu *rebootMenu;
00364
00365
00366
00367 QAction *cutAct;
00368 QAction *copyAct;
00369 QAction *pasteAct;
00370 QAction *undoAct;
00371 QAction *redoAct;
00372 QAction *showHiddenAct;
00373 QAction* showCompilationMsg;
00374
00375
00376 CompilationLogDialog *compilationMessageBox;
00377 QString actualFileName;
00378 bool sourceModified;
00379 QTextBrowser* helpViewer;
00380
00381
00382 CommonDefinitions commonDefinitions;
00383 Compiler compiler;
00384 Target *target;
00385 };
00386
00388 };
00389
00390 #endif
00391