HAL
content_manager.cpp
Go to the documentation of this file.
15 #include "gui/gui_globals.h"
16 #include "gui/gui_utils/graphics.h"
17 #include "gui/gui_utils/sort.h"
34 
35 #include <QGraphicsScene>
36 #include <QGraphicsView>
37 #include <QOpenGLWidget>
38 
39 namespace hal
40 {
41 
42  ExternalContent* ExternalContent::inst = nullptr;
43 
45  {
46  if (!inst)
47  inst = new ExternalContent;
48  return inst;
49  }
50 
51  ExternalContentWidget::ExternalContentWidget(const QString& pluginName, const QString& windowName, QWidget* parent)
52  : ContentWidget(windowName,parent), mPluginName(pluginName)
53  {
54  ExternalContent::instance()->openWidgets.insert(mPluginName,this);
55  }
56 
58  {
59  ExternalContent::instance()->openWidgets.remove(mPluginName);
60  }
61 
62  SettingsItemDropdown* ContentManager::sSettingSortMechanism;
65  bool ContentManager::sSettingsInitialized = initializeSettings();
66  bool ContentManager::initializeSettings()
67  {
68  sSettingSortMechanism = new SettingsItemDropdown(
69  "Sort Mechanism", "navigation/sort_mechanism", gui_utility::mSortMechanism::lexical, "eXpert Settings:Miscellaneous", "Specifies the sort mechanism used in every list ");
70  sSettingSortMechanism->setValueNames<gui_utility::mSortMechanism>();
71 
73  new SettingsItemKeybind("Search",
74  "keybinds/searchbar_toggle",
75  QKeySequence("Ctrl+F"),
76  "Keybindings:Global",
77  "Keybind for toggeling the searchbar in widgets where available (Selection Details Widget, Modules Widget, Python Editor, Views Widget, Grouping Widget).");
78 
79 
81  new SettingsItemKeybind("Delete Item",
82  "keybinds/item_delete",
83  QKeySequence("Del"),
84  "Keybindings:Global",
85  "Keybind for deleting the focused Item.");
86  return true;
87  }
88 
89  ContentManager::ContentManager(MainWindow* parent) : QObject(parent), mMainWindow(parent),
90  mExternalIndex(0),
91  mPythonConsoleWidget(nullptr),
92  mPythonWidget(nullptr),
93  mGraphTabWidget(nullptr),
94  mModuleWidget(nullptr),
95  mContextManagerWidget(nullptr),
96  mGroupingManagerWidget(nullptr),
97  mSelectionDetailsWidget(nullptr),
98  mLoggerWidget(nullptr),
99  mContextSerializer(nullptr)
100  {
101 
102 
103  // has to be created this early in order to receive deserialization by the core signals
104  mPythonWidget = new PythonEditor();
105 
107  //connect(FileManager::get_instance(), &FileManager::fileChanged, this, &ContentManager::handleFilsystemDocChanged);
108  }
109 
111  {
112  }
113 
115  {
116  auto it = ExternalContent::instance()->openWidgets.begin();
117  while (it != ExternalContent::instance()->openWidgets.end())
118  {
119  it.value()->deleteLater();
120  it = ExternalContent::instance()->openWidgets.erase(it);
121  }
122  for (auto content : mContent)
123  delete content;
124 
125  mContent.clear();
126 
127  //m_python_widget = nullptr; DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
128 
129  mPythonConsoleWidget = nullptr;
130 // mPythonWidget = nullptr;
131  mGraphTabWidget = nullptr;
132  mModuleWidget = nullptr;
133  mContextManagerWidget = nullptr;
134  mGroupingManagerWidget = nullptr;
135  mSelectionDetailsWidget = nullptr;
136  mLoggerWidget = nullptr;
137  if (mContextSerializer) delete mContextSerializer;
138  }
139 
141  {
142  return mPythonWidget;
143  }
144 
146  {
147  return mGraphTabWidget;
148  }
149 
151  {
152  return mSelectionDetailsWidget;
153  }
154 
156  {
157  return mGroupingManagerWidget;
158  }
159 
161  {
162  return mModuleWidget;
163  }
164 
166  {
167  return mContextManagerWidget;
168  }
169 
171  {
172  mExternalIndex = 1;
173 
174  mGraphTabWidget = new GraphTabWidget();
175  mMainWindow->addContent(mGraphTabWidget, 0, content_anchor::center);
176 
177  mModuleWidget = new ModuleWidget();
178  mMainWindow->addContent(mModuleWidget, 0, content_anchor::left);
179  mModuleWidget->open();
180 
181  mContextManagerWidget = new ContextManagerWidget(mGraphTabWidget);
182  mMainWindow->addContent(mContextManagerWidget, 1, content_anchor::left);
183  mContextManagerWidget->open();
184 
185  mGroupingManagerWidget = new GroupingManagerWidget();
186  mMainWindow->addContent(mGroupingManagerWidget, 2, content_anchor::left);
187  mGroupingManagerWidget->open();
188 
189  //we should probably document somewhere why we need this timer and why we have some sort of racing condition(?) here?
190  //QTimer::singleShot(50, [this]() { this->mContextManagerWid->handleCreateContextClicked(); });
191 
192  //executes same code as found in 'create_context_clicked' from the context manager widget but allows to keep its method private
193  /*
194  QTimer::singleShot(50, [this]() {
195 
196  GraphContext* new_context = nullptr;
197  new_context = gGraphContextManager->createNewContext(QString::fromStdString(gNetlist->get_top_module()->get_name()));
198  new_context->add({gNetlist->get_top_module()->get_id()}, {});
199 
200  mContextManagerWidget->selectViewContext(new_context);
201  gGraphContextManager->restoreFromFile();
202  new_context->setDirty(false);
203  });
204 */
205  //why does this segfault without a timer?
206  //GraphContext* new_context = nullptr;
207  //new_context = gGraphContextManager->createNewContext(QString::fromStdString(gNetlist->get_top_module()->get_name()));
208  //new_context->add({gNetlist->get_top_module()->get_id()}, {});
209  //mContextManagerWid->selectViewContext(new_context);
210 
211  mSelectionDetailsWidget = new SelectionDetailsWidget();
212  mMainWindow->addContent(mSelectionDetailsWidget, 0, content_anchor::bottom);
213  mSelectionDetailsWidget->open();
214 
215  mLoggerWidget = new LoggerWidget();
216  mMainWindow->addContent(mLoggerWidget, 1, content_anchor::bottom);
217 
218  mMainWindow->addContent(mPythonWidget, 3, content_anchor::right);
219  mPythonWidget->open();
220 
221  mPythonConsoleWidget = new PythonConsoleWidget();
222  mMainWindow->addContent(mPythonConsoleWidget, 2, content_anchor::bottom);
223  mPythonConsoleWidget->open();
224 
225  mContent.append(mGraphTabWidget);
226  mContent.append(mModuleWidget);
227  mContent.append(mContextManagerWidget);
228  mContent.append(mGroupingManagerWidget);
229  mContent.append(mSelectionDetailsWidget);
230  mContent.append(mLoggerWidget);
231  //mContent.append(mPythonWidget); // DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
232  mContent.append(mPythonConsoleWidget);
233 
234  setWindowTitle(fileName);
235 
236 #ifdef HAL_STUDY
237  //log_info("gui", "HAL_STUDY activated");
238  mSpecialLogContentManager = new SpecialLogContentManager(mMainWindow, mPythonWidget);
239  mSpecialLogContentManager->startLogging(60000);
240 #endif
241  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mSelectionDetailsWidget, [this](int value) {
242  mSelectionDetailsWidget->selectionTreeView()->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
243  });
244 
245  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mModuleWidget, [this](int value) { mModuleWidget->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value)); });
246 
247  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mGroupingManagerWidget, [this](int value) {
248  mGroupingManagerWidget->getProxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
249  });
250 
251  sSettingSortMechanism->intChanged(sSettingSortMechanism->value().toInt());
252 
258 
260 
261  GraphContext* selectedContext = nullptr;
262 
263 // mContextManagerWidget->selectViewContext(new_context);
264 
265  // try to restore from project directory
266  mContextSerializer = new GraphContextSerializer;
267  if (mContextSerializer->restore())
268  {
269  selectedContext = mContextSerializer->selectedContext();
270  }
271  else
272  {
273  selectedContext = topModuleContextFactory();
274  gGraphContextManager->restoreFromFile(fileName + "v");
275  }
276 
278  {
279  addExternalWidget(cf);
280  }
281 
282  if (selectedContext)
283  mContextManagerWidget->selectViewContext(selectedContext);
284  mContextManagerWidget->handleOpenContextClicked();
285 
287  geif->netlist_loaded(gNetlist);
288 
289  }
290 
292  {
293  ContentWidget* cw = factory->contentFactory();
294  mMainWindow->addContent(cw, mExternalIndex++, content_anchor::right);
295  cw->open();
296  cw->restoreFromProject();
297  }
298 
299  GraphContext* ContentManager::topModuleContextFactory()
300  {
301  Module* top_module = gNetlist->get_top_module();
302  if (!top_module) return nullptr;
303  QString context_name = QString::fromStdString(top_module->get_name()) + " (ID: " + QString::number(top_module->get_id()) + ")";
304  GraphContext* retval = gGraphContextManager->createNewContext(context_name);
305  retval->add({top_module->get_id()}, {});
306  retval->setExclusiveModuleId(top_module->get_id());
307  retval->setDirty(false);
308  return retval;
309  }
310 
312  {
313  mWindowTitle = "HAL - " + QString::fromStdString(std::filesystem::path(filename.toStdString()).stem().string());
314  mMainWindow->setWindowTitle(mWindowTitle);
315  }
316 } // namespace hal
virtual ExternalContentWidget * contentFactory() const =0
GraphTabWidget * getGraphTabWidget()
Get hal's graph tab widget.
SelectionDetailsWidget * getSelectionDetailsWidget()
PythonEditor * getPythonEditorWidget()
ContentManager(MainWindow *parent)
void handleOpenDocument(const QString &fileName)
static SettingsItemKeybind * sSettingDeleteItem
GroupingManagerWidget * getGroupingManagerWidget()
static SettingsItemKeybind * sSettingSearch
ModuleWidget * getModuleWidget()
void setWindowTitle(const QString &filename)
void addExternalWidget(ContentFactory *factory)
ContextManagerWidget * getContextManagerWidget()
Abstract class for Widgets within HAL's ContentArea.
virtual void restoreFromProject()
void handleSearchKeysequenceChanged(QKeySequence seq)
Provides the user with an interface to manage GraphContexts.
void selectViewContext(GraphContext *context)
static ExternalContent * instance()
QMap< QString, ExternalContentWidget * > openWidgets
ExternalContentWidget(const QString &pluginName, const QString &windowName, QWidget *parent=nullptr)
static FileManager * get_instance()
void fileOpened(const QString &fileName)
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
void setDirty(bool dty)
void setExclusiveModuleId(u32 id, bool emitSignal=true)
void add(const QSet< u32 > &modules, const QSet< u32 > &gates, PlacementHint placement=PlacementHint())
GraphContext * createNewContext(const QString &name, u32 parentId=0)
GraphContext * restoreFromFile(const QString &filename)
bool restore(const std::filesystem::path &loaddir=std::filesystem::path())
GraphContext * selectedContext() const
A ContentWidget that holds all GraphWidget objects (GraphView) as tabs of a QTabWidget.
User interface for Groupings.
GroupingProxyModel * getProxyModel() const
static QMap< QString, GuiExtensionInterface * > getGuiExtensions()
Displays the logs in the gui.
Definition: logger_widget.h:57
The top level widget.
Definition: main_window.h:65
void addContent(ContentWidget *widget, int index, content_anchor anchor)
std::string get_name() const
Definition: module.cpp:87
u32 get_id() const
Definition: module.cpp:82
Shows the modules of the netlist hierarchical in a tree view.
Definition: module_widget.h:59
ModuleProxyModel * proxyModel()
Module * get_top_module() const
Definition: netlist.cpp:608
Wraps the PythonConsole.
Main widget that combines all neccessary functionality to develop in python (for hal).
Definition: python_editor.h:99
Container for all specific details widgets.
A SettingsItem that represents a dropdown menu.
virtual QVariant value() const override
void intChanged(int value)
A SettingsItem to modify keybinds.
void keySequenceChanged(QKeySequence value)
virtual QVariant value() const override
Logs the python editor and gui screenshots.
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
Netlist * gNetlist
Definition: plugin_gui.cpp:80
QList::iterator end()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString fromStdString(const std::string &str)
QString number(int n, int base)
std::string toStdString() const const
int toInt(bool *ok) const const
QString toString() const const
void setWindowTitle(const QString &)