1 /////////////////////////////////////////////////////////////////////////////// 2 // BSD 3-Clause License 3 // 4 // Copyright (c) 2019, The Regents of the University of California 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions are met: 9 // 10 // * Redistributions of source code must retain the above copyright notice, this 11 // list of conditions and the following disclaimer. 12 // 13 // * Redistributions in binary form must reproduce the above copyright notice, 14 // this list of conditions and the following disclaimer in the documentation 15 // and/or other materials provided with the distribution. 16 // 17 // * Neither the name of the copyright holder nor the names of its 18 // contributors may be used to endorse or promote products derived from 19 // this software without specific prior written permission. 20 // 21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 // POSSIBILITY OF SUCH DAMAGE. 32 33 #pragma once 34 35 #include <QAction> 36 #include <QLabel> 37 #include <QMainWindow> 38 #include <QToolBar> 39 #include <memory> 40 #include <typeindex> 41 42 #include "findDialog.h" 43 #include "gui/gui.h" 44 #include "ord/OpenRoad.hh" 45 #include "timingDebugDialog.h" 46 47 namespace odb { 48 class dbDatabase; 49 } 50 51 namespace utl { 52 class Logger; 53 } 54 55 namespace gui { 56 57 class LayoutViewer; 58 class SelectHighlightWindow; 59 class LayoutScroll; 60 class ScriptWidget; 61 class DisplayControls; 62 class Inspector; 63 64 // This is the main window for the GUI. Currently we use a single 65 // instance of this class. 66 class MainWindow : public QMainWindow, public ord::OpenRoad::Observer 67 { 68 Q_OBJECT 69 70 public: 71 MainWindow(QWidget* parent = nullptr); 72 getDb()73 odb::dbDatabase* getDb() const { return db_; } 74 void setDb(odb::dbDatabase* db); 75 76 // From ord::OpenRoad::Observer 77 virtual void postReadLef(odb::dbTech* tech, odb::dbLib* library) override; 78 virtual void postReadDef(odb::dbBlock* block) override; 79 virtual void postReadDb(odb::dbDatabase* db) override; 80 81 // Capture logger messages into the script widget output 82 void setLogger(utl::Logger* logger); 83 84 // Fit design in window 85 void fit(); 86 87 void registerDescriptor(const std::type_info& type, 88 const Descriptor* descriptor); 89 90 signals: 91 // Signaled when we get a postRead callback to tell the sub-widgets 92 // to update 93 void designLoaded(odb::dbBlock* block); 94 95 // The user chose the exit action; notify the app 96 void exit(); 97 98 // Trigger a redraw (used by Renderers) 99 void redraw(); 100 101 // Waits for the user to click continue before returning 102 // Draw events are processed while paused. 103 void pause(); 104 105 // The selected set of objects has changed 106 void selectionChanged(); 107 108 // The highlight set of objects has changed 109 void highlightChanged(); 110 111 // Ruler Requested on the Layout 112 void rulersChanged(); 113 114 public slots: 115 // Save the current state into settings for the next session. 116 void saveSettings(); 117 118 // Set the location to display in the status bar 119 void setLocation(qreal x, qreal y); 120 121 // Add to the selection 122 void addSelected(const Selected& selection); 123 124 // Add the selections to the current selections 125 void addSelected(const SelectionSet& selections); 126 127 // Make an Selected from object with a known descriptor 128 Selected makeSelected(std::any object, 129 void* additional_data = nullptr); 130 131 // Displays the selection in the status bar 132 void setSelected(const Selected& selection, bool show_connectivity = false); 133 134 // Add the selections to highlight set 135 void addHighlighted(const SelectionSet& selection, int highlight_group = 0); 136 137 // Add Ruler to Layout View 138 void addRuler(int x0, int y0, int x1, int y1); 139 140 // Add the selections(List) to highlight set 141 void updateHighlightedSet(const QList<const Selected*>& items_to_highlight, 142 int highlight_group = 0); 143 144 // Higlight set will be cleared with this explicit call 145 void clearHighlighted(int highlight_group = -1 /* -1 : clear all Groups */); 146 147 // Clear Rulers 148 void clearRulers(); 149 150 // Remove items from the Selected Set 151 void removeFromSelected(const QList<const Selected*>& items); 152 153 // Remove items from the Highlighted Set 154 void removeFromHighlighted(const QList<const Selected*>& items, 155 int highlight_group 156 = -1 /* Search and remove...*/); 157 158 // Zoom to the given rectangle 159 void zoomTo(const odb::Rect& rect_dbu); 160 161 // Zoom In To Items such that its bbox is in visible Area 162 void zoomInToItems(const QList<const Selected*>& items); 163 164 // Show a message in the status bar 165 void status(const std::string& message); 166 167 // Show Find Dialog Box 168 void showFindDialog(); 169 170 // show Timing Dialog Box 171 void showTimingDialog(); 172 getControls()173 DisplayControls* getControls() const { return controls_; } 174 175 bool anyObjectInSet(bool selection_set, odb::dbObjectType obj_type); 176 void selectHighlightConnectedInsts(bool select_flag, int highlight_group = 0); 177 void selectHighlightConnectedNets(bool select_flag, 178 bool output, 179 bool input, 180 int highlight_group = 0); 181 182 private: 183 void createMenus(); 184 void createActions(); 185 void createToolbars(); 186 void createStatusBar(); 187 188 odb::dbBlock* getBlock(); 189 190 odb::dbDatabase* db_; 191 SelectionSet selected_; 192 HighlightSet highlighted_; 193 std::vector<QLine> rulers_; 194 195 // All but viewer_ are owned by this widget. Qt will 196 // handle destroying the children. 197 DisplayControls* controls_; 198 Inspector* inspector_; 199 LayoutViewer* viewer_; // owned by scroll_ 200 SelectHighlightWindow* selection_browser_; 201 LayoutScroll* scroll_; 202 ScriptWidget* script_; 203 204 QMenu* file_menu_; 205 QMenu* view_menu_; 206 QMenu* tools_menu_; 207 QMenu* windows_menu_; 208 209 QToolBar* view_tool_bar_; 210 211 QAction* exit_; 212 QAction* fit_; 213 QAction* find_; 214 QAction* inspect_; 215 QAction* timing_debug_; 216 QAction* zoom_in_; 217 QAction* zoom_out_; 218 219 QAction* congestion_setup_; 220 221 QLabel* location_; 222 223 FindObjectDialog* find_dialog_; 224 TimingDebugDialog* timing_dialog_; 225 226 // Maps types to descriptors 227 std::unordered_map<std::type_index, const Descriptor*> descriptors_; 228 }; 229 230 } // namespace gui 231