HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
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 
40 namespace hal
41 {
42 
43  ExternalContent* ExternalContent::inst = nullptr;
44 
46  {
47  if (!inst)
48  inst = new ExternalContent;
49  return inst;
50  }
51 
52  void ExternalContent::removePlugin(const QString& pluginName)
53  {
54  auto it = begin();
55  while (it != end())
56  if ((*it)->name() == pluginName)
57  it = erase(it);
58  else
59  ++it;
60 
61  for (;;)
62  {
63  auto itw = openWidgets.find(pluginName);
64  if (itw == openWidgets.end()) break;
65 
66  itw.value()->remove();
67  itw.value()->deleteLater();
68  openWidgets.erase(itw);
69  }
70  }
71 
72  ExternalContentWidget::ExternalContentWidget(const QString& pluginName, const QString& windowName, QWidget* parent)
73  : ContentWidget(windowName,parent), mPluginName(pluginName)
74  {
75  ExternalContent::instance()->openWidgets.insert(mPluginName,this);
76  }
77 
79 
80  SettingsItemDropdown* ContentManager::sSettingSortMechanism;
83  bool ContentManager::sSettingsInitialized = initializeSettings();
84  bool ContentManager::initializeSettings()
85  {
86  sSettingSortMechanism = new SettingsItemDropdown(
87  "Sort Mechanism", "navigation/sort_mechanism", gui_utility::mSortMechanism::lexical, "eXpert Settings:Miscellaneous", "Specifies the sort mechanism used in every list ");
88  sSettingSortMechanism->setValueNames<gui_utility::mSortMechanism>();
89 
91  new SettingsItemKeybind("Search",
92  "keybinds/searchbar_toggle",
93  QKeySequence("Ctrl+F"),
94  "Keybindings:Global",
95  "Keybind for toggeling the searchbar in widgets where available (Selection Details Widget, Modules Widget, Python Editor, Views Widget, Grouping Widget).");
96 
97 
99  new SettingsItemKeybind("Delete Item",
100  "keybinds/item_delete",
101  QKeySequence("Del"),
102  "Keybindings:Global",
103  "Keybind for deleting the focused Item.");
104  return true;
105  }
106 
107  ContentManager::ContentManager(MainWindow* parent) : QObject(parent), mMainWindow(parent),
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 
140  //mPythonWidget = nullptr; DONT DO THIS PYTHON_WIDGET IS CREATED IN THE CONSTRUCTOR FOR SOME REASON
141 
142  mPythonConsoleWidget->deleteLater();
143  mPythonConsoleWidget = nullptr;
144  mGraphTabWidget->deleteLater();
145  mGraphTabWidget = nullptr;
146  mModuleWidget->deleteLater();
147  mModuleWidget = nullptr;
148  mContextManagerWidget->deleteLater();
149  mContextManagerWidget = nullptr;
150  mGroupingManagerWidget->deleteLater();
151  mGroupingManagerWidget = nullptr;
152  mSelectionDetailsWidget->deleteLater();
153  mSelectionDetailsWidget = nullptr;
154  mLoggerWidget->deleteLater();
155  mLoggerWidget = nullptr;
156  if (mContextSerializer) delete mContextSerializer;
157  }
158 
160  {
161  return mPythonWidget;
162  }
163 
165  {
166  return mGraphTabWidget;
167  }
168 
170  {
171  return mSelectionDetailsWidget;
172  }
173 
175  {
176  return mGroupingManagerWidget;
177  }
178 
180  {
181  return mModuleWidget;
182  }
183 
185  {
186  return mContextManagerWidget;
187  }
188 
190  {
191  int rightIndex = 1;
192 
193  mGraphTabWidget = new GraphTabWidget;
194  mModuleWidget = new ModuleWidget;
195  mContextManagerWidget = new ContextManagerWidget(mGraphTabWidget);
196  mGroupingManagerWidget = new GroupingManagerWidget;
197  mSelectionDetailsWidget = new SelectionDetailsWidget;
198  mLoggerWidget = new LoggerWidget;
199  mPythonConsoleWidget = new PythonConsoleWidget;
200 
201  QList<ContentWidgetPlacement> contentPlaceList;
202  contentPlaceList.append({mGraphTabWidget, 0, ContentLayout::Position::Center, true});
203  contentPlaceList.append({mModuleWidget, 0, ContentLayout::Position::Left, true});
204  contentPlaceList.append({mContextManagerWidget, 1, ContentLayout::Position::Left, true});
205  contentPlaceList.append({mGroupingManagerWidget, 2, ContentLayout::Position::Left, true});
206  contentPlaceList.append({mSelectionDetailsWidget, 0, ContentLayout::Position::Bottom, true});
207  contentPlaceList.append({mLoggerWidget, 1, ContentLayout::Position::Bottom, false});
208  contentPlaceList.append({mPythonConsoleWidget, 2, ContentLayout::Position::Bottom, true});
209  contentPlaceList.append({mPythonWidget, 0, ContentLayout::Position::Right, true});
210 
212  {
213  ContentWidget* cw = cf->contentFactory();
214  cw->restoreFromProject();
215  contentPlaceList.append({cw, rightIndex++, ContentLayout::Position::Right, true});
216  }
217 
218  for (ContentWidgetPlacement& cwp : contentPlaceList)
219  {
220  ContentWidgetPlacement settingPlacement = SettingsManager::instance()->widgetPlacement(cwp.widget);
221  if (settingPlacement.index >= 0)
222  cwp = settingPlacement;
223  }
224 
225  int placeIndex = 0;
226  while (!contentPlaceList.isEmpty())
227  {
228  auto it = contentPlaceList.begin();
229  while (it != contentPlaceList.end())
230  {
231  if (it->index == placeIndex)
232  {
233  mMainWindow->addContent(it->widget, it->index, it->anchorPos);
234  if (it->visible) it->widget->open();
235 
237  it = contentPlaceList.erase(it);
238  }
239  else
240  ++it;
241  }
242  ++placeIndex;
243  }
244 
245  setWindowTitle(fileName);
246 
247 #ifdef HAL_STUDY
248  //log_info("gui", "HAL_STUDY activated");
249  mSpecialLogContentManager = new SpecialLogContentManager(mMainWindow, mPythonWidget);
250  mSpecialLogContentManager->startLogging(60000);
251 #endif
252  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mSelectionDetailsWidget, [this](int value) {
253  mSelectionDetailsWidget->selectionTreeView()->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
254  });
255 
256  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mModuleWidget, [this](int value) { mModuleWidget->proxyModel()->setSortMechanism(gui_utility::mSortMechanism(value)); });
257 
258  connect(sSettingSortMechanism, &SettingsItemDropdown::intChanged, mGroupingManagerWidget, [this](int value) {
259  mGroupingManagerWidget->getProxyModel()->setSortMechanism(gui_utility::mSortMechanism(value));
260  });
261 
262  sSettingSortMechanism->intChanged(sSettingSortMechanism->value().toInt());
263 
269 
271 
272  GraphContext* selectedContext = nullptr;
273 
274 // mContextManagerWidget->selectViewContext(new_context);
275 
276  // try to restore from project directory
277  mContextSerializer = new GraphContextSerializer;
278  if (mContextSerializer->restore())
279  {
280  selectedContext = mContextSerializer->selectedContext();
281  }
282  else
283  {
284  selectedContext = topModuleContextFactory();
285  gGraphContextManager->restoreFromFile(fileName + "v");
286  }
287 
288  if (selectedContext)
289  mContextManagerWidget->selectViewContext(selectedContext);
290  mContextManagerWidget->handleOpenContextClicked();
291 
293  geif->netlist_loaded(gNetlist);
294 
295  mMainWindow->layoutArea()->restoreSplitter();
296  }
297 
299  {
300  ContentWidget* cw = factory->contentFactory();
301  mMainWindow->addContent(cw, 1, ContentLayout::Position::Right);
302  cw->open();
303  cw->restoreFromProject();
304  }
305 
306  GraphContext* ContentManager::topModuleContextFactory()
307  {
308  Module* top_module = gNetlist->get_top_module();
309  if (!top_module) return nullptr;
310  QString context_name = QString::fromStdString(top_module->get_name()) + " (ID: " + QString::number(top_module->get_id()) + ")";
311  GraphContext* retval = gGraphContextManager->createNewContext(context_name);
312  retval->add({top_module->get_id()}, {});
313  retval->setExclusiveModuleId(top_module->get_id());
314  retval->setDirty(false);
315  return retval;
316  }
317 
319  {
320  mWindowTitle = "HAL - " + QString::fromStdString(std::filesystem::path(filename.toStdString()).stem().string());
321  mMainWindow->setWindowTitle(mWindowTitle);
322  }
323 } // 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:88
u32 get_id() const
Definition: module.cpp:83
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:610
Wraps the PythonConsole.
Main widget that combines all neccessary functionality to develop in python (for hal).
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.
Definition: defines.h:45
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:86
Netlist * gNetlist
Definition: gui_globals.h:69
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 &)