1 /*
2  *  nextpnr -- Next Generation Place and Route
3  *
4  *  Copyright (C) 2018  Miodrag Milanovic <miodrag@symbioticeda.com>
5  *
6  *  Permission to use, copy, modify, and/or distribute this software for any
7  *  purpose with or without fee is hereby granted, provided that the above
8  *  copyright notice and this permission notice appear in all copies.
9  *
10  *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  */
19 
20 #ifndef BASEMAINWINDOW_H
21 #define BASEMAINWINDOW_H
22 
23 #include "command.h"
24 #include "nextpnr.h"
25 #include "worker.h"
26 
27 #include <QMainWindow>
28 #include <QMenu>
29 #include <QMenuBar>
30 #include <QProgressBar>
31 #include <QStatusBar>
32 #include <QTabWidget>
33 #include <QToolBar>
34 
35 Q_DECLARE_METATYPE(std::string)
36 Q_DECLARE_METATYPE(NEXTPNR_NAMESPACE_PREFIX DecalXY)
37 
38 NEXTPNR_NAMESPACE_BEGIN
39 
40 class PythonTab;
41 class DesignWidget;
42 class FPGAViewWidget;
43 
44 class BaseMainWindow : public QMainWindow
45 {
46     Q_OBJECT
47 
48   public:
49     explicit BaseMainWindow(std::unique_ptr<Context> context, CommandHandler *handler, QWidget *parent = 0);
50     virtual ~BaseMainWindow();
getContext()51     Context *getContext() { return ctx.get(); }
52     void updateActions();
53 
54     void notifyChangeContext();
55 
56   protected:
57     void createMenusAndBars();
58     void disableActions();
59     void enableDisableDecals();
60 
onDisableActions()61     virtual void onDisableActions(){};
onUpdateActions()62     virtual void onUpdateActions(){};
63 
64   protected Q_SLOTS:
65     void writeInfo(std::string text);
66     void closeTab(int index);
67 
68     virtual void new_proj() = 0;
69 
70     void open_json();
71     void save_json();
72     void budget();
73     void place();
74 
75     void execute_python();
76 
77     void pack_finished(bool status);
78     void budget_finish(bool status);
79     void place_finished(bool status);
80     void route_finished(bool status);
81 
82     void taskCanceled();
83     void taskStarted();
84     void taskPaused();
85 
86     void screenshot();
87     void saveMovie();
88     void saveSVG();
89 
90   Q_SIGNALS:
91     void contextChanged(Context *ctx);
92     void updateTreeView();
93 
94   protected:
95     // state variables
96     CommandHandler *handler;
97     std::unique_ptr<Context> ctx;
98     TaskManager *task;
99     bool timing_driven;
100     std::string currentProj;
101 
102     // main widgets
103     QTabWidget *tabWidget;
104     QTabWidget *centralTabWidget;
105     PythonTab *console;
106     DesignWidget *designview;
107     FPGAViewWidget *fpgaView;
108 
109     // Menus, bars and actions
110     QMenuBar *menuBar;
111     QMenu *menuDesign;
112     QStatusBar *statusBar;
113     QToolBar *mainActionBar;
114     QProgressBar *progressBar;
115 
116     QAction *actionNew;
117     QAction *actionLoadJSON;
118     QAction *actionSaveJSON;
119 
120     QAction *actionPack;
121     QAction *actionAssignBudget;
122     QAction *actionPlace;
123     QAction *actionRoute;
124 
125     QAction *actionExecutePy;
126 
127     QAction *actionPlay;
128     QAction *actionPause;
129     QAction *actionStop;
130 
131     QAction *actionDisplayBel;
132     QAction *actionDisplayWire;
133     QAction *actionDisplayPip;
134     QAction *actionDisplayGroups;
135 
136     QAction *actionScreenshot;
137     QAction *actionMovie;
138     QAction *actionSaveSVG;
139 };
140 
141 NEXTPNR_NAMESPACE_END
142 
143 #endif // BASEMAINWINDOW_H
144