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  for (auto content : mContent)
117  delete content;
118 
119  mContent.clear();
120 
121  //m_python_widget = nullptr; DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
122 
123  mPythonConsoleWidget = nullptr;
124 // mPythonWidget = nullptr;
125  mGraphTabWidget = nullptr;
126  mModuleWidget = nullptr;
127  mContextManagerWidget = nullptr;
128  mGroupingManagerWidget = nullptr;
129  mSelectionDetailsWidget = nullptr;
130  mLoggerWidget = nullptr;
131  if (mContextSerializer) delete mContextSerializer;
132  }
133 
135  {
136  return mPythonWidget;
137  }
138 
140  {
141  return mGraphTabWidget;
142  }
143 
145  {
146  return mSelectionDetailsWidget;
147  }
148 
150  {
151  return mGroupingManagerWidget;
152  }
153 
155  {
156  return mModuleWidget;
157  }
158 
160  {
161  return mContextManagerWidget;
162  }
163 
165  {
166  mExternalIndex = 1;
167 
168  mGraphTabWidget = new GraphTabWidget();
169  mMainWindow->addContent(mGraphTabWidget, 0, content_anchor::center);
170 
171  mModuleWidget = new ModuleWidget();
172  mMainWindow->addContent(mModuleWidget, 0, content_anchor::left);
173  mModuleWidget->open();
174 
175  mContextManagerWidget = new ContextManagerWidget(mGraphTabWidget);
176  mMainWindow->addContent(mContextManagerWidget, 1, content_anchor::left);
177  mContextManagerWidget->open();
178 
179  mGroupingManagerWidget = new GroupingManagerWidget();
180  mMainWindow->addContent(mGroupingManagerWidget, 2, content_anchor::left);
181  mGroupingManagerWidget->open();
182 
183  //we should probably document somewhere why we need this timer and why we have some sort of racing condition(?) here?
184  //QTimer::singleShot(50, [this]() { this->mContextManagerWid->handleCreateContextClicked(); });
185 
186  //executes same code as found in 'create_context_clicked' from the context manager widget but allows to keep its method private
187  /*
188  QTimer::singleShot(50, [this]() {
189 
190  GraphContext* new_context = nullptr;
191  new_context = gGraphContextManager->createNewContext(QString::fromStdString(gNetlist->get_top_module()->get_name()));
192  new_context->add({gNetlist->get_top_module()->get_id()}, {});
193 
194  mContextManagerWidget->selectViewContext(new_context);
195  gGraphContextManager->restoreFromFile();
196  new_context->setDirty(false);
197  });
198 */
199  //why does this segfault without a timer?
200  //GraphContext* new_context = nullptr;
201  //new_context = gGraphContextManager->createNewContext(QString::fromStdString(gNetlist->get_top_module()->get_name()));
202  //new_context->add({gNetlist->get_top_module()->get_id()}, {});
203  //mContextManagerWid->selectViewContext(new_context);
204 
205  mSelectionDetailsWidget = new SelectionDetailsWidget();
206  mMainWindow->addContent(mSelectionDetailsWidget, 0, content_anchor::bottom);
207  mSelectionDetailsWidget->open();
208 
209  mLoggerWidget = new LoggerWidget();
210  mMainWindow->addContent(mLoggerWidget, 1, content_anchor::bottom);
211 
212  mMainWindow->addContent(mPythonWidget, 3, content_anchor::right);
213  mPythonWidget->open();
214 
215  mPythonConsoleWidget = new PythonConsoleWidget();
216  mMainWindow->addContent(mPythonConsoleWidget, 2, content_anchor::bottom);
217  mPythonConsoleWidget->open();
218 
219  mContent.append(mGraphTabWidget);
220  mContent.append(mModuleWidget);
221  mContent.append(mContextManagerWidget);
222  mContent.append(mGroupingManagerWidget);
223  mContent.append(mSelectionDetailsWidget);
224  mContent.append(mLoggerWidget);
225  //mContent.append(mPythonWidget); // DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
226  mContent.append(mPythonConsoleWidget);
227 
228  setWindowTitle(fileName);
229 
230 #ifdef HAL_STUDY
231  //log_info("gui", "HAL_STUDY activated");
232  mSpecialLogContentManager = new SpecialLogContentManager(mMainWindow, mPythonWidget);
233  mSpecialLogContentManager->startLogging(60000);
234 #endif
235  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mSelectionDetailsWidget, [this](int value) {
236  mSelectionDetailsWidget->selectionTreeView()->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
237  });
238 
239  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mModuleWidget, [this](int value) { mModuleWidget->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value)); });
240 
241  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mGroupingManagerWidget, [this](int value) {
242  mGroupingManagerWidget->getProxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
243  });
244 
245  sSettingSortMechanism->intChanged(sSettingSortMechanism->value().toInt());
246 
252 
254 
255  GraphContext* selectedContext = nullptr;
256 
257 // mContextManagerWidget->selectViewContext(new_context);
258 
259  // try to restore from project directory
260  mContextSerializer = new GraphContextSerializer;
261  if (mContextSerializer->restore())
262  {
263  selectedContext = mContextSerializer->selectedContext();
264  }
265  else
266  {
267  selectedContext = topModuleContextFactory();
268  gGraphContextManager->restoreFromFile(fileName + "v");
269  }
270 
272  {
273  addExternalWidget(cf);
274  }
275 
276  if (selectedContext)
277  mContextManagerWidget->selectViewContext(selectedContext);
278  mContextManagerWidget->handleOpenContextClicked();
279 
281  geif->netlist_loaded(gNetlist);
282 
283  }
284 
286  {
287  ContentWidget* cw = factory->contentFactory();
288  mMainWindow->addContent(cw, mExternalIndex++, content_anchor::right);
289  cw->open();
290  cw->restoreFromProject();
291  }
292 
293  GraphContext* ContentManager::topModuleContextFactory()
294  {
295  Module* top_module = gNetlist->get_top_module();
296  if (!top_module) return nullptr;
297  QString context_name = QString::fromStdString(top_module->get_name()) + " (ID: " + QString::number(top_module->get_id()) + ")";
298  GraphContext* retval = gGraphContextManager->createNewContext(context_name);
299  retval->add({top_module->get_id()}, {});
300  retval->setExclusiveModuleId(top_module->get_id());
301  retval->setDirty(false);
302  return retval;
303  }
304 
306  {
307  mWindowTitle = "HAL - " + QString::fromStdString(std::filesystem::path(filename.toStdString()).stem().string());
308  mMainWindow->setWindowTitle(mWindowTitle);
309  }
310 } // 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
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 &)