1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // BSD 3-Clause License
4 //
5 // Copyright (c) 2020, The Regents of the University of California
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // * Redistributions of source code must retain the above copyright notice, this
12 // list of conditions and the following disclaimer.
13 //
14 // * Redistributions in binary form must reproduce the above copyright notice,
15 // this list of conditions and the following disclaimer in the documentation
16 // and/or other materials provided with the distribution.
17 //
18 // * Neither the name of the copyright holder nor the names of its
19 // contributors may be used to endorse or promote products derived from
20 // this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35
36 %{
37 #include "ord/OpenRoad.hh"
38 #include "utl/Logger.h"
39 #include "gui/gui.h"
40
41 using utl::GUI;
42 %}
43
44 %inline %{
45
enabled()46 bool enabled()
47 {
48 auto gui = gui::Gui::get();
49 return gui != nullptr;
50 }
51
52 void
selection_add_net(const char * name)53 selection_add_net(const char* name)
54 {
55 auto gui = gui::Gui::get();
56 if (!gui) {
57 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 13, "Command selection_add_net is not usable in non-GUI mode");
58 return;
59 }
60 gui->addSelectedNet(name);
61 }
62
63 void
selection_add_nets(const char * name)64 selection_add_nets(const char* name)
65 {
66 auto gui = gui::Gui::get();
67 if (!gui) {
68 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 5, "Command selection_add_nets is not usable in non-GUI mode");
69 return;
70 }
71 gui->addSelectedNets(name);
72 }
73
74 void
selection_add_inst(const char * name)75 selection_add_inst(const char* name)
76 {
77 auto gui = gui::Gui::get();
78 if (!gui) {
79 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 6, "Command selection_add_inst is not usable in non-GUI mode");
80 return;
81 }
82 gui->addSelectedInst(name);
83 }
84
85 void
selection_add_insts(const char * name)86 selection_add_insts(const char* name)
87 {
88 auto gui = gui::Gui::get();
89 if (!gui) {
90 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 7, "Command selection_add_insts is not usable in non-GUI mode");
91 return;
92 }
93 gui->addSelectedInsts(name);
94 }
95
highlight_inst(const char * name,int highlightGroup)96 void highlight_inst(const char* name, int highlightGroup)
97 {
98 auto gui = gui::Gui::get();
99 if (!gui) {
100 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 8, "Command highlight_inst is not usable in non-GUI mode");
101 return;
102 }
103 gui->addInstToHighlightSet(name, highlightGroup);
104 }
105
106 void highlight_net(const char* name, int highlightGroup=0)
107 {
108 auto gui = gui::Gui::get();
109 if (!gui) {
110 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 9, "Command highlight_net is not usable in non-GUI mode");
111 return;
112 }
113 gui->addNetToHighlightSet(name, highlightGroup);
114 }
115
add_ruler(int x0,int y0,int x1,int y1)116 void add_ruler(int x0, int y0, int x1, int y1)
117 {
118 auto gui = gui::Gui::get();
119 if (!gui) {
120 ord::OpenRoad::openRoad()->getLogger()->info(GUI, 10, "Command add_ruler is not usable in non-GUI mode");
121 return ;
122 }
123 gui->addRuler(x0, y0, x1, y1);
124 }
125
126 // converts from microns to DBU
zoom_to(double xlo,double ylo,double xhi,double yhi)127 void zoom_to(double xlo, double ylo, double xhi, double yhi)
128 {
129 auto gui = gui::Gui::get();
130 auto logger = ord::OpenRoad::openRoad()->getLogger();
131 if (!gui) {
132 logger->info(GUI, 11, "Command zoom_to is not usable in non-GUI mode");
133 return ;
134 }
135 auto db = ord::OpenRoad::openRoad()->getDb();
136 if (!db) {
137 logger->error(GUI, 1, "No database loaded");
138 }
139 auto chip = db->getChip();
140 if (!chip) {
141 logger->error(GUI, 2, "No chip loaded");
142 }
143 auto block = chip->getBlock();
144 if (!block) {
145 logger->error(GUI, 3, "No block loaded");
146 }
147
148 int dbuPerUU = block->getDbUnitsPerMicron();
149 odb::Rect rect(xlo * dbuPerUU, ylo * dbuPerUU, xhi * dbuPerUU, yhi * dbuPerUU);
150 gui->zoomTo(rect);
151 }
152
design_created()153 void design_created()
154 {
155 auto gui = gui::Gui::get();
156 if (!gui) {
157 auto logger = ord::OpenRoad::openRoad()->getLogger();
158 logger->info(GUI, 12, "Command design_created is not usable in non-GUI mode");
159 return;
160 }
161 gui->load_design();
162 }
163
fit()164 void fit()
165 {
166 auto gui = gui::Gui::get();
167 if (!gui) {
168 auto logger = ord::OpenRoad::openRoad()->getLogger();
169 logger->info(GUI, 14, "Command fit is not usable in non-GUI mode");
170 return;
171 }
172 gui->fit();
173 }
174 %} // inline
175
176