HAL
content_manager.cpp
Go to the documentation of this file.
13 #include "gui/gui_globals.h"
14 #include "gui/gui_utils/sort.h"
30 /*
31 #include "gui/content_layout_area/content_layout_area.h"
32 #include "gui/graph_widget/graph_graphics_view.h"
33 #include "gui/gui_utils/graphics.h"
34 #include "hal_core/plugin_system/plugin_interface_base.h"
35 #include "hal_core/plugin_system/plugin_manager.h"
36 */
37 #include <QGraphicsScene>
38 #include <QGraphicsView>
39 #include <QOpenGLWidget>
40 
41 namespace hal
42 {
43 
44  ExternalContent* ExternalContent::inst = nullptr;
45 
47  {
48  if (!inst)
49  inst = new ExternalContent;
50  return inst;
51  }
52 
53  void ExternalContent::removePlugin(const QString& pluginName)
54  {
55  auto it = begin();
56  while (it != end())
57  if ((*it)->name() == pluginName)
58  it = erase(it);
59  else
60  ++it;
61 
62  for (;;)
63  {
64  auto itw = openWidgets.find(pluginName);
65  if (itw == openWidgets.end()) break;
66 
67  itw.value()->remove();
68  itw.value()->deleteLater();
69  openWidgets.erase(itw);
70  }
71  }
72 
73  ExternalContentWidget::ExternalContentWidget(const QString& pluginName, const QString& windowName, QWidget* parent)
74  : ContentWidget(windowName,parent), mPluginName(pluginName)
75  {
76  ExternalContent::instance()->openWidgets.insert(mPluginName,this);
77  }
78 
80 
81  SettingsItemDropdown* ContentManager::sSettingSortMechanism;
84  bool ContentManager::sSettingsInitialized = initializeSettings();
85  bool ContentManager::initializeSettings()
86  {
87  sSettingSortMechanism = new SettingsItemDropdown(
88  "Sort Mechanism", "navigation/sort_mechanism", gui_utility::mSortMechanism::lexical, "eXpert Settings:Miscellaneous", "Specifies the sort mechanism used in every list ");
89  sSettingSortMechanism->setValueNames<gui_utility::mSortMechanism>();
90 
92  new SettingsItemKeybind("Search",
93  "keybinds/searchbar_toggle",
94  QKeySequence("Ctrl+F"),
95  "Keybindings:Global",
96  "Keybind for toggeling the searchbar in widgets where available (Selection Details Widget, Modules Widget, Python Editor, Views Widget, Grouping Widget).");
97 
98 
100  new SettingsItemKeybind("Delete Item",
101  "keybinds/item_delete",
102  QKeySequence("Del"),
103  "Keybindings:Global",
104  "Keybind for deleting the focused Item.");
105  return true;
106  }
107 
108  ContentManager::ContentManager(MainWindow* parent) : QObject(parent), mMainWindow(parent),
109  mPythonConsoleWidget(nullptr),
110  mPythonWidget(nullptr),
111  mGraphTabWidget(nullptr),
112  mModuleWidget(nullptr),
113  mContextManagerWidget(nullptr),
114  mGroupingManagerWidget(nullptr),
115  mSelectionDetailsWidget(nullptr),
116  mLoggerWidget(nullptr),
117  mContextSerializer(nullptr)
118  {
119 
120 
121  // has to be created this early in order to receive deserialization by the core signals
122  mPythonWidget = new PythonEditor();
123 
125  //connect(FileManager::get_instance(), &FileManager::fileChanged, this, &ContentManager::handleFilsystemDocChanged);
126  }
127 
129  {
130  }
131 
133  {
134  auto it = ExternalContent::instance()->openWidgets.begin();
135  while (it != ExternalContent::instance()->openWidgets.end())
136  {
137  it.value()->deleteLater();
138  it = ExternalContent::instance()->openWidgets.erase(it);
139  }
140 
141  //mPythonWidget = nullptr; DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
142 
143  mPythonConsoleWidget->deleteLater();
144  mPythonConsoleWidget = nullptr;
145  mGraphTabWidget->deleteLater();
146  mGraphTabWidget = nullptr;
147  mModuleWidget->deleteLater();
148  mModuleWidget = nullptr;
149  mContextManagerWidget->deleteLater();
150  mContextManagerWidget = nullptr;
151  mGroupingManagerWidget->deleteLater();
152  mGroupingManagerWidget = nullptr;
153  mSelectionDetailsWidget->deleteLater();
154  mSelectionDetailsWidget = nullptr;
155  mLoggerWidget->deleteLater();
156  mLoggerWidget = nullptr;
157  if (mContextSerializer) delete mContextSerializer;
158  }
159 
161  {
162  return mPythonWidget;
163  }
164 
166  {
167  return mGraphTabWidget;
168  }
169 
171  {
172  return mSelectionDetailsWidget;
173  }
174 
176  {
177  return mGroupingManagerWidget;
178  }
179 
181  {
182  return mModuleWidget;
183  }
184 
186  {
187  return mContextManagerWidget;
188  }
189 
191  {
192  int rightIndex = 1;
193 
194  mGraphTabWidget = new GraphTabWidget;
195  mModuleWidget = new ModuleWidget;
196  mContextManagerWidget = new ContextManagerWidget(mGraphTabWidget);
197  mGroupingManagerWidget = new GroupingManagerWidget;
198  mSelectionDetailsWidget = new SelectionDetailsWidget;
199  mLoggerWidget = new LoggerWidget;
200  mPythonConsoleWidget = new PythonConsoleWidget;
201 
202  QList<ContentWidgetPlacement> contentPlaceList;
203  contentPlaceList.append({mGraphTabWidget, 0, ContentLayout::Position::Center, true});
204  contentPlaceList.append({mModuleWidget, 0, ContentLayout::Position::Left, true});
205  contentPlaceList.append({mContextManagerWidget, 1, ContentLayout::Position::Left, true});
206  contentPlaceList.append({mGroupingManagerWidget, 2, ContentLayout::Position::Left, true});
207  contentPlaceList.append({mSelectionDetailsWidget, 0, ContentLayout::Position::Bottom, true});
208  contentPlaceList.append({mLoggerWidget, 1, ContentLayout::Position::Bottom, false});
209  contentPlaceList.append({mPythonConsoleWidget, 2, ContentLayout::Position::Bottom, true});
210  contentPlaceList.append({mPythonWidget, 0, ContentLayout::Position::Right, true});
211 
213  {
214  ContentWidget* cw = cf->contentFactory();
215  cw->restoreFromProject();
216  contentPlaceList.append({cw, rightIndex++, ContentLayout::Position::Right, true});
217  }
218 
219  for (ContentWidgetPlacement& cwp : contentPlaceList)
220  {
221  ContentWidgetPlacement settingPlacement = SettingsManager::instance()->widgetPlacement(cwp.widget);
222  if (settingPlacement.index >= 0)
223  cwp = settingPlacement;
224  }
225 
226  int placeIndex = 0;
227  while (!contentPlaceList.isEmpty())
228  {
229  auto it = contentPlaceList.begin();
230  while (it != contentPlaceList.end())
231  {
232  if (it->index == placeIndex)
233  {
234  mMainWindow->addContent(it->widget, it->index, it->anchorPos);
235  if (it->visible) it->widget->open();
236 
238  it = contentPlaceList.erase(it);
239  }
240  else
241  ++it;
242  }
243  ++placeIndex;
244  }
245 
246  setWindowTitle(fileName);
247 
248 #ifdef HAL_STUDY
249  //log_info("gui", "HAL_STUDY activated");
250  mSpecialLogContentManager = new SpecialLogContentManager(mMainWindow, mPythonWidget);
251  mSpecialLogContentManager->startLogging(60000);
252 #endif
253  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mSelectionDetailsWidget, [this](int value) {
254  mSelectionDetailsWidget->selectionTreeView()->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
255  });
256 
257  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mModuleWidget, [this](int value) { mModuleWidget->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value)); });
258 
259  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mGroupingManagerWidget, [this](int value) {
260  mGroupingManagerWidget->getProxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
261  });
262 
263  sSettingSortMechanism->intChanged(sSettingSortMechanism->value().toInt());
264 
270 
272 
273  GraphContext* selectedContext = nullptr;
274 
275 // mContextManagerWidget->selectViewContext(new_context);
276 
277  // try to restore from project directory
278  mContextSerializer = new GraphContextSerializer;
279  if (mContextSerializer->restore())
280  {
281  selectedContext = mContextSerializer->selectedContext();
282  }
283  else
284  {
285  selectedContext = topModuleContextFactory();
286  gGraphContextManager->restoreFromFile(fileName + "v");
287  }
288 
289  if (selectedContext)
290  mContextManagerWidget->selectViewContext(selectedContext);
291  mContextManagerWidget->handleOpenContextClicked();
292 
294  geif->netlist_loaded(gNetlist);
295 
296  mMainWindow->layoutArea()->restoreSplitter();
297  }
298 
300  {
301  ContentWidget* cw = factory->contentFactory();
302  mMainWindow->addContent(cw, 1, ContentLayout::Position::Right);
303  cw->open();
304  cw->restoreFromProject();
305  }
306 
307  GraphContext* ContentManager::topModuleContextFactory()
308  {
309  Module* top_module = gNetlist->get_top_module();
310  if (!top_module) return nullptr;
311  QString context_name = QString::fromStdString(top_module->get_name()) + " (ID: " + QString::number(top_module->get_id()) + ")";
312  GraphContext* retval = gGraphContextManager->createNewContext(context_name);
313  retval->add({top_module->get_id()}, {});
314  retval->setExclusiveModuleId(top_module->get_id());
315  retval->setDirty(false);
316  return retval;
317  }
318 
320  {
321  mWindowTitle = "HAL - " + QString::fromStdString(std::filesystem::path(filename.toStdString()).stem().string());
322  mMainWindow->setWindowTitle(mWindowTitle);
323  }
324 } // 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
ContentLayoutArea * layoutArea() const
void addContent(ContentWidget *widget, int index, ContentLayout::Position 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
void widgetDetach(ContentWidget *cw) const
static SettingsManager * instance()
ContentWidgetPlacement widgetPlacement(ContentWidget *cw) const
Logs the python editor and gui screenshots.
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
Netlist * gNetlist
Definition: plugin_gui.cpp:80
void append(const T &value)
QList::iterator begin()
QList::iterator end()
QList::iterator erase(QList::iterator pos)
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void deleteLater()
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 &)