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  void ExternalContent::removePlugin(const QString& pluginName)
52  {
53  auto it = begin();
54  while (it != end())
55  if ((*it)->name() == pluginName)
56  it = erase(it);
57  else
58  ++it;
59 
60  for (;;)
61  {
62  auto itw = openWidgets.find(pluginName);
63  if (itw == openWidgets.end()) break;
64 
65  itw.value()->remove();
66  itw.value()->deleteLater();
67  openWidgets.erase(itw);
68  }
69  }
70 
71  ExternalContentWidget::ExternalContentWidget(const QString& pluginName, const QString& windowName, QWidget* parent)
72  : ContentWidget(windowName,parent), mPluginName(pluginName)
73  {
74  ExternalContent::instance()->openWidgets.insert(mPluginName,this);
75  }
76 
78 
79  SettingsItemDropdown* ContentManager::sSettingSortMechanism;
82  bool ContentManager::sSettingsInitialized = initializeSettings();
83  bool ContentManager::initializeSettings()
84  {
85  sSettingSortMechanism = new SettingsItemDropdown(
86  "Sort Mechanism", "navigation/sort_mechanism", gui_utility::mSortMechanism::lexical, "eXpert Settings:Miscellaneous", "Specifies the sort mechanism used in every list ");
87  sSettingSortMechanism->setValueNames<gui_utility::mSortMechanism>();
88 
90  new SettingsItemKeybind("Search",
91  "keybinds/searchbar_toggle",
92  QKeySequence("Ctrl+F"),
93  "Keybindings:Global",
94  "Keybind for toggeling the searchbar in widgets where available (Selection Details Widget, Modules Widget, Python Editor, Views Widget, Grouping Widget).");
95 
96 
98  new SettingsItemKeybind("Delete Item",
99  "keybinds/item_delete",
100  QKeySequence("Del"),
101  "Keybindings:Global",
102  "Keybind for deleting the focused Item.");
103  return true;
104  }
105 
106  ContentManager::ContentManager(MainWindow* parent) : QObject(parent), mMainWindow(parent),
107  mExternalIndex(0),
108  mPythonConsoleWidget(nullptr),
109  mPythonWidget(nullptr),
110  mGraphTabWidget(nullptr),
111  mModuleWidget(nullptr),
112  mContextManagerWidget(nullptr),
113  mGroupingManagerWidget(nullptr),
114  mSelectionDetailsWidget(nullptr),
115  mLoggerWidget(nullptr),
116  mContextSerializer(nullptr)
117  {
118 
119 
120  // has to be created this early in order to receive deserialization by the core signals
121  mPythonWidget = new PythonEditor();
122 
124  //connect(FileManager::get_instance(), &FileManager::fileChanged, this, &ContentManager::handleFilsystemDocChanged);
125  }
126 
128  {
129  }
130 
132  {
133  auto it = ExternalContent::instance()->openWidgets.begin();
134  while (it != ExternalContent::instance()->openWidgets.end())
135  {
136  it.value()->deleteLater();
137  it = ExternalContent::instance()->openWidgets.erase(it);
138  }
139  for (auto content : mContent)
140  delete content;
141 
142  mContent.clear();
143 
144  //m_python_widget = nullptr; DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
145 
146  mPythonConsoleWidget = nullptr;
147 // mPythonWidget = nullptr;
148  mGraphTabWidget = nullptr;
149  mModuleWidget = nullptr;
150  mContextManagerWidget = nullptr;
151  mGroupingManagerWidget = nullptr;
152  mSelectionDetailsWidget = nullptr;
153  mLoggerWidget = nullptr;
154  if (mContextSerializer) delete mContextSerializer;
155  }
156 
158  {
159  return mPythonWidget;
160  }
161 
163  {
164  return mGraphTabWidget;
165  }
166 
168  {
169  return mSelectionDetailsWidget;
170  }
171 
173  {
174  return mGroupingManagerWidget;
175  }
176 
178  {
179  return mModuleWidget;
180  }
181 
183  {
184  return mContextManagerWidget;
185  }
186 
188  {
189  mExternalIndex = 1;
190 
191  mGraphTabWidget = new GraphTabWidget();
192  mMainWindow->addContent(mGraphTabWidget, 0, content_anchor::center);
193 
194  mModuleWidget = new ModuleWidget();
195  mMainWindow->addContent(mModuleWidget, 0, content_anchor::left);
196  mModuleWidget->open();
197 
198  mContextManagerWidget = new ContextManagerWidget(mGraphTabWidget);
199  mMainWindow->addContent(mContextManagerWidget, 1, content_anchor::left);
200  mContextManagerWidget->open();
201 
202  mGroupingManagerWidget = new GroupingManagerWidget();
203  mMainWindow->addContent(mGroupingManagerWidget, 2, content_anchor::left);
204  mGroupingManagerWidget->open();
205 
206  //we should probably document somewhere why we need this timer and why we have some sort of racing condition(?) here?
207  //QTimer::singleShot(50, [this]() { this->mContextManagerWid->handleCreateContextClicked(); });
208 
209  //executes same code as found in 'create_context_clicked' from the context manager widget but allows to keep its method private
210  /*
211  QTimer::singleShot(50, [this]() {
212 
213  GraphContext* new_context = nullptr;
214  new_context = gGraphContextManager->createNewContext(QString::fromStdString(gNetlist->get_top_module()->get_name()));
215  new_context->add({gNetlist->get_top_module()->get_id()}, {});
216 
217  mContextManagerWidget->selectViewContext(new_context);
218  gGraphContextManager->restoreFromFile();
219  new_context->setDirty(false);
220  });
221 */
222  //why does this segfault without a timer?
223  //GraphContext* new_context = nullptr;
224  //new_context = gGraphContextManager->createNewContext(QString::fromStdString(gNetlist->get_top_module()->get_name()));
225  //new_context->add({gNetlist->get_top_module()->get_id()}, {});
226  //mContextManagerWid->selectViewContext(new_context);
227 
228  mSelectionDetailsWidget = new SelectionDetailsWidget();
229  mMainWindow->addContent(mSelectionDetailsWidget, 0, content_anchor::bottom);
230  mSelectionDetailsWidget->open();
231 
232  mLoggerWidget = new LoggerWidget();
233  mMainWindow->addContent(mLoggerWidget, 1, content_anchor::bottom);
234 
235  mMainWindow->addContent(mPythonWidget, 3, content_anchor::right);
236  mPythonWidget->open();
237 
238  mPythonConsoleWidget = new PythonConsoleWidget();
239  mMainWindow->addContent(mPythonConsoleWidget, 2, content_anchor::bottom);
240  mPythonConsoleWidget->open();
241 
242  mContent.append(mGraphTabWidget);
243  mContent.append(mModuleWidget);
244  mContent.append(mContextManagerWidget);
245  mContent.append(mGroupingManagerWidget);
246  mContent.append(mSelectionDetailsWidget);
247  mContent.append(mLoggerWidget);
248  //mContent.append(mPythonWidget); // DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
249  mContent.append(mPythonConsoleWidget);
250 
251  setWindowTitle(fileName);
252 
253 #ifdef HAL_STUDY
254  //log_info("gui", "HAL_STUDY activated");
255  mSpecialLogContentManager = new SpecialLogContentManager(mMainWindow, mPythonWidget);
256  mSpecialLogContentManager->startLogging(60000);
257 #endif
258  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mSelectionDetailsWidget, [this](int value) {
259  mSelectionDetailsWidget->selectionTreeView()->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
260  });
261 
262  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mModuleWidget, [this](int value) { mModuleWidget->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value)); });
263 
264  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mGroupingManagerWidget, [this](int value) {
265  mGroupingManagerWidget->getProxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
266  });
267 
268  sSettingSortMechanism->intChanged(sSettingSortMechanism->value().toInt());
269 
275 
277 
278  GraphContext* selectedContext = nullptr;
279 
280 // mContextManagerWidget->selectViewContext(new_context);
281 
282  // try to restore from project directory
283  mContextSerializer = new GraphContextSerializer;
284  if (mContextSerializer->restore())
285  {
286  selectedContext = mContextSerializer->selectedContext();
287  }
288  else
289  {
290  selectedContext = topModuleContextFactory();
291  gGraphContextManager->restoreFromFile(fileName + "v");
292  }
293 
295  {
296  addExternalWidget(cf);
297  }
298 
299  if (selectedContext)
300  mContextManagerWidget->selectViewContext(selectedContext);
301  mContextManagerWidget->handleOpenContextClicked();
302 
304  geif->netlist_loaded(gNetlist);
305 
306  }
307 
309  {
310  ContentWidget* cw = factory->contentFactory();
311  mMainWindow->addContent(cw, mExternalIndex++, content_anchor::right);
312  cw->open();
313  cw->restoreFromProject();
314  }
315 
316  GraphContext* ContentManager::topModuleContextFactory()
317  {
318  Module* top_module = gNetlist->get_top_module();
319  if (!top_module) return nullptr;
320  QString context_name = QString::fromStdString(top_module->get_name()) + " (ID: " + QString::number(top_module->get_id()) + ")";
321  GraphContext* retval = gGraphContextManager->createNewContext(context_name);
322  retval->add({top_module->get_id()}, {});
323  retval->setExclusiveModuleId(top_module->get_id());
324  retval->setDirty(false);
325  return retval;
326  }
327 
329  {
330  mWindowTitle = "HAL - " + QString::fromStdString(std::filesystem::path(filename.toStdString()).stem().string());
331  mMainWindow->setWindowTitle(mWindowTitle);
332  }
333 } // 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()
void removePlugin(const QString &pluginName)
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 begin()
QList::iterator end()
QList::iterator erase(QList::iterator pos)
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 &)