Skip to content

Commit 89ddeaf

Browse files
Finalized code, added NoC button
1 parent eb7ba2b commit 89ddeaf

File tree

7 files changed

+131
-87
lines changed

7 files changed

+131
-87
lines changed

vpr/main.ui

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,35 @@
103103
<property name="position">5</property>
104104
</packing>
105105
</child>
106+
<child>
107+
<object class="GtkLabel" id="NocLabel">
108+
<property name="visible">True</property>
109+
<property name="can_focus">False</property>
110+
<property name="label" translatable="yes">Toggle NoC Display</property>
111+
</object>
112+
<packing>
113+
<property name="expand">False</property>
114+
<property name="fill">True</property>
115+
<property name="position">6</property>
116+
</packing>
117+
</child>
118+
<child>
119+
<object class="GtkComboBoxText" id="ToggleNocBox">
120+
<property name="visible">True</property>
121+
<property name="can_focus">False</property>
122+
<property name="active">0</property>
123+
<items>
124+
<item translatable="yes">None</item>
125+
<item translatable="yes">NoC Links</item>
126+
<item translatable="yes">NoC Link Usage</item>
127+
</items>
128+
</object>
129+
<packing>
130+
<property name="expand">False</property>
131+
<property name="fill">True</property>
132+
<property name="position">7</property>
133+
</packing>
134+
</child>
106135
<child>
107136
<object class="GtkCheckButton" id="blockOutline">
108137
<property name="label" translatable="yes">Block Outline</property>
@@ -116,7 +145,7 @@
116145
<packing>
117146
<property name="expand">False</property>
118147
<property name="fill">True</property>
119-
<property name="position">6</property>
148+
<property name="position">8</property>
120149
</packing>
121150
</child>
122151
<child>
@@ -132,7 +161,7 @@
132161
<packing>
133162
<property name="expand">False</property>
134163
<property name="fill">True</property>
135-
<property name="position">7</property>
164+
<property name="position">9</property>
136165
</packing>
137166
</child>
138167
</object>

vpr/src/draw/buttons.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,6 @@ gint label_left_start_col = 0;
2828
gint box_left_start_col = 0;
2929
gint button_row = 2; // 2 is the row num of the window button in main.ui, add buttons starting from this row
3030

31-
void button_for_displaying_noc() {
32-
GObject* main_window = application.get_object(application.get_main_window_id().c_str());
33-
GObject* main_window_grid = application.get_object("InnerGrid");
34-
t_draw_state* draw_state = get_draw_state_vars();
35-
36-
// if the user did not turn on the "noc" option then we don't give the option to display the noc to the user
37-
if (!draw_state->show_noc_button) {
38-
return;
39-
}
40-
41-
// if we are here then the user turned the "noc" option on, so create a button to allow the user to display the noc
42-
43-
//combo box for toggle_noc_display
44-
GtkWidget* toggle_noc_display_widget = gtk_combo_box_text_new();
45-
GtkWidget* toggle_noc_display_label = gtk_label_new("Toggle NoC Display:");
46-
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(toggle_noc_display_widget), "None");
47-
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(toggle_noc_display_widget), "NoC Links");
48-
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(toggle_noc_display_widget), "NoC Link Usage");
49-
50-
gtk_combo_box_set_active((GtkComboBox*)toggle_noc_display_widget, 0); // default set to None which has an index 0
51-
gtk_widget_set_name(toggle_noc_display_widget, "toggle_noc_display");
52-
53-
//attach to the grid
54-
gtk_grid_attach((GtkGrid*)main_window_grid, toggle_noc_display_label, label_left_start_col, button_row++, box_width, box_height);
55-
gtk_grid_attach((GtkGrid*)main_window_grid, toggle_noc_display_widget, box_left_start_col, button_row++, box_width, box_height);
56-
57-
// show the newy added check box
58-
gtk_widget_show_all((GtkWidget*)main_window);
59-
60-
//connect signals
61-
g_signal_connect_swapped(GTK_COMBO_BOX_TEXT(toggle_noc_display_widget),
62-
"changed",
63-
G_CALLBACK(toggle_noc_display),
64-
toggle_noc_display_widget);
65-
}
66-
6731
void delete_button(const char* button_name) {
6832
GObject* main_window_grid = application.get_object("InnerGrid");
6933
GList* list_of_widgets = gtk_container_get_children(GTK_CONTAINER(main_window_grid));

vpr/src/draw/buttons.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# include "ezgl/application.hpp"
1010
# include "ezgl/graphics.hpp"
1111

12-
void button_for_displaying_noc();
13-
1412
void delete_button(const char* button_name);
1513
GtkWidget* find_button(const char* button_name);
1614
#endif /* NO_GRAPHICS */

vpr/src/draw/draw.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ static void initial_setup_NO_PICTURE_to_PLACEMENT(ezgl::application* app,
302302
//Hiding unused functionality
303303
hide_widget("RoutingMenuButton", app);
304304
hide_crit_path_button(app);
305-
button_for_displaying_noc();
306305
}
307306

308307
/* function below intializes the interface window with a set of buttons and links
@@ -357,7 +356,6 @@ static void initial_setup_NO_PICTURE_to_ROUTING(ezgl::application* app,
357356
default_setup(app);
358357
routing_button_setup(app);
359358
hide_crit_path_button(app);
360-
button_for_displaying_noc();
361359
}
362360

363361
/* function below intializes the interface window with a set of buttons and links
@@ -680,8 +678,8 @@ void act_on_key_press(ezgl::application* app, GdkEventKey* /*event*/, char* key_
680678
//VTR_LOG("Key press %c (%d)\n", key_pressed, keysym);
681679
std::string key(key_name);
682680
std::cout << "Pressed key" << std::endl;
683-
if(gtk_widget_is_focus(GTK_WIDGET(app->get_object("TextInput")))){
684-
if(key == "Return"){
681+
if (gtk_widget_is_focus(GTK_WIDGET(app->get_object("TextInput")))) {
682+
if (key == "Return") {
685683
enable_autocomplete(app);
686684
}
687685
}
@@ -691,8 +689,8 @@ void act_on_key_press(ezgl::application* app, GdkEventKey* /*event*/, char* key_
691689
std::cout << "Pressed key" << std::endl;
692690
std::string key(key_name);
693691
GtkWidget* searchBar = GTK_WIDGET(app->get_object("TextInput"));
694-
if(gtk_widget_is_focus(searchBar)){
695-
if(key == "Return"){
692+
if (gtk_widget_is_focus(searchBar)) {
693+
if (key == "Return") {
696694
std::string oldText(gtk_entry_get_text(GTK_ENTRY(searchBar)));
697695
enable_autocomplete(app);
698696
gtk_editable_set_position(GTK_EDITABLE(searchBar), oldText.length());

vpr/src/draw/draw_toggle_functions.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,19 @@ void toggle_expansion_cost_cbk(GtkComboBoxText* self, ezgl::application* app) {
406406
app->refresh_drawing();
407407
}
408408

409-
void toggle_noc_display(GtkWidget* /*widget*/, gint /*response_id*/, gpointer /*data*/) {
409+
/**
410+
* @brief cbk fn to toggle Network-On-Chip (Noc) visibility
411+
* alters draw_state->draw_noc to reflect new state
412+
*
413+
* @param self ptr to combo box
414+
* @param app ezgl application
415+
*/
416+
void toggle_noc_cbk(GtkComboBoxText* self, ezgl::application* app) {
410417
/* this is the callback function for runtime created toggle_noc_display button
411418
* which is written in button.cpp */
412419
t_draw_state* draw_state = get_draw_state_vars();
413-
std::string button_name = "toggle_noc_display";
414-
auto toggle_crit_path = find_button(button_name.c_str());
415420

416-
gchar* combo_box_content = gtk_combo_box_text_get_active_text(
417-
GTK_COMBO_BOX_TEXT(toggle_crit_path));
421+
gchar* combo_box_content = gtk_combo_box_text_get_active_text(self);
418422
if (strcmp(combo_box_content, "None") == 0) {
419423
draw_state->draw_noc = DRAW_NO_NOC;
420424
} else if (strcmp(combo_box_content, "NoC Links") == 0)
@@ -423,7 +427,7 @@ void toggle_noc_display(GtkWidget* /*widget*/, gint /*response_id*/, gpointer /*
423427
draw_state->draw_noc = DRAW_NOC_LINK_USAGE;
424428

425429
g_free(combo_box_content);
426-
application.refresh_drawing();
430+
app->refresh_drawing();
427431
}
428432

429433
/**

vpr/src/draw/draw_toggle_functions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,10 @@ void toggle_crit_path_cbk(GtkComboBoxText* self, ezgl::application* app);
107107
* Draws different router expansion costs based on user input. Changes value of draw_state->show_router_expansion_cost. */
108108
void toggle_expansion_cost_cbk(GtkComboBoxText* self, ezgl::application* app);
109109

110-
/* Callback function for runtime created toggle_noc_display
111-
* in button.cpp.
110+
/* Callback function for main.ui created ToggleNocBox in ui_setup.cpp
112111
* Controls if the NoC on chip should be visualized and whether the link usage
113112
* in the NoC should be visualized. Changes value of draw_state->draw_noc */
114-
void toggle_noc_display(GtkWidget* widget, gint /*response_id*/, gpointer /*data*/);
113+
void toggle_noc_cbk(GtkComboBoxText* self, ezgl::application* app);
115114

116115
/* Callback function for main.ui created netMaxFanout widget in button.cpp.
117116
* Sets draw_state->draw_net_max_fanout to its corresponding value in the UI. */

vpr/src/draw/search_bar.cpp

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* @file search_bar.cpp
3+
* @author Sebastian Lievano
4+
* @brief Contains search/auto-complete related functions
5+
* @version 0.1
6+
* @date 2022-07-20
7+
*
8+
* This file essentially follows the whole search process, from searching, finding the match,
9+
* and finally highlighting the searched for item. Additionally, auto-complete related stuff is found
10+
* here.
11+
*
12+
* @copyright Copyright (c) 2022
13+
*
14+
*/
15+
116
#ifndef NO_GRAPHICS
217
# include <cstdio>
318
# include <sstream>
@@ -94,20 +109,25 @@ void search_and_highlight(GtkWidget* /*widget*/, ezgl::application* app) {
94109
}
95110

96111
else if (search_type == "Block Name") {
112+
/* If the block exists in atom netlist, proceeding with highlighting process.
113+
* if highlight atom block fn returns false, that means that the block can't be highlighted
114+
* We've already confirmed the block exists in the netlist, so that means that at this zoom lvl,
115+
* the subblock is not shown. Therefore highlight the clb mapping.
116+
*
117+
* If the block does not exist in the atom netlist, we will check the CLB netlist to see if
118+
* they searched for a cluster block*/
97119
std::string block_name = "";
98120
ss >> block_name;
99121

100-
AtomBlockId atom_blk_id = AtomBlockId::INVALID();
101-
atom_blk_id = atom_ctx.nlist.find_block(block_name);
102-
//If block is found, the CLB containing it is highlighted
122+
AtomBlockId atom_blk_id = atom_ctx.nlist.find_block(block_name);
103123
if (atom_blk_id != AtomBlockId::INVALID()) {
104124
ClusterBlockId block_id = atom_ctx.lookup.atom_clb(atom_blk_id);
105-
//Highlighting atom block. IF function returns false, highlighting clb that contains
106125
if (!highlight_atom_block(atom_blk_id, block_id, app)) {
107126
highlight_cluster_block(block_id);
108127
}
109128
return;
110129
}
130+
111131
//Continues if atom block not found (Checking if user searched a clb)
112132
ClusterBlockId block_id = ClusterBlockId::INVALID();
113133
block_id = cluster_ctx.clb_nlist.find_block(block_name);
@@ -134,10 +154,11 @@ void search_and_highlight(GtkWidget* /*widget*/, ezgl::application* app) {
134154
}
135155

136156
else if (search_type == "Net Name") {
157+
//in this case, all nets (clb and non-clb) are contained in the atom netlist
158+
//So we only need to search this one
137159
std::string net_name = "";
138160
ss >> net_name;
139-
AtomNetId atom_net_id = AtomNetId::INVALID();
140-
atom_net_id = atom_ctx.nlist.find_net(net_name);
161+
AtomNetId atom_net_id = atom_ctx.nlist.find_net(net_name);
141162

142163
if (atom_net_id == AtomNetId::INVALID()) {
143164
warning_dialog_box("Invalid Net Name");
@@ -314,7 +335,7 @@ bool highlight_atom_block(AtomBlockId atom_blk, ClusterBlockId cl_blk, ezgl::app
314335
*
315336
* @param name name of block being searched for
316337
* @param pb current node to be examined
317-
* @return t_pb* t_pb ptr of block w. name "name"
338+
* @return t_pb* t_pb ptr of block w. name "name". Returns nullptr if nothing found
318339
*/
319340
t_pb* find_atom_block_in_pb(std::string name, t_pb* pb) {
320341
//Checking if block is one being searched for
@@ -350,6 +371,7 @@ void highlight_nets(ClusterNetId net_id) {
350371

351372
t_draw_state* draw_state = get_draw_state_vars();
352373

374+
//If routing does not exist return
353375
if (int(route_ctx.trace.size()) == 0) return;
354376

355377
for (tptr = route_ctx.trace[net_id].head; tptr != nullptr; tptr = tptr->next) {
@@ -422,8 +444,8 @@ void search_type_changed(GtkComboBox* self, ezgl::application* app) {
422444
}
423445

424446
/**
425-
* @brief A new matching function used for the wildcard search options
426-
* Will be slower
447+
* @brief A non-default matching function. As opposed to simply searching for a prefix(default),
448+
* searches string for presence of a substring. Ignores cases.
427449
*
428450
* @param completer the GtkEntryCompletion being used
429451
* @param key a normalized and case-folded key representing the text
@@ -448,46 +470,76 @@ gboolean customMatchingFunction(
448470
return (cppText.find(key, 0) != std::string::npos);
449471
}
450472

451-
void enable_autocomplete(ezgl::application* app){
473+
/**
474+
* @brief Creates a GdkEvent that simulates user pressing key "key"
475+
*
476+
* @param key character value
477+
* @param window GdkWindow
478+
* @return GdkEvent Keypress event
479+
*/
480+
GdkEvent simulate_keypress(char key, GdkWindow* window) {
481+
int charVal = (int)key;
482+
//Creating event and adding properties
483+
GdkEvent new_event;
484+
new_event.key.type = GDK_KEY_PRESS;
485+
new_event.key.window = window;
486+
new_event.key.send_event = TRUE;
487+
new_event.key.time = GDK_CURRENT_TIME;
488+
new_event.key.keyval = gdk_unicode_to_keyval(charVal);
489+
new_event.key.state = GDK_KEY_PRESS_MASK;
490+
new_event.key.length = 0;
491+
new_event.key.string = 0;
492+
new_event.key.hardware_keycode = 0;
493+
new_event.key.group = 0;
494+
return new_event;
495+
}
496+
497+
/**
498+
* @brief Turns on autocomplete
499+
*
500+
* This function enables the auto-complete fuctionality for the search bar.
501+
* Normally, this is pretty simple, but the idea is to have auto-complete appear as soon
502+
* as the user hits the "Enter" key. To accomplish this, a fake Gdk event is created
503+
* to simulate the user hitting a key.
504+
*
505+
* @param app ezgl app
506+
*/
507+
void enable_autocomplete(ezgl::application* app) {
452508
std::cout << "enabling autocomplete" << std::endl;
453509
GtkEntryCompletion* completion = GTK_ENTRY_COMPLETION(app->get_object("Completion"));
454510
GtkEntry* searchBar = GTK_ENTRY(app->get_object("TextInput"));
511+
455512
std::string searchType = get_search_type(app);
456-
if(gtk_entry_completion_get_model(completion) == NULL){
513+
//Checking to make sure that we are on a mode that uses auto-complete
514+
if (gtk_entry_completion_get_model(completion) == NULL) {
457515
std::cout << "NO MODEL SELECTED" << std::endl;
458516
return;
459517
}
518+
519+
//Getting input text
460520
std::string oldText(gtk_entry_get_text(searchBar));
521+
522+
//Turning on completion
461523
gtk_entry_set_completion(searchBar, completion);
462-
gtk_entry_completion_set_minimum_key_length(completion, std::max(0, (int)(oldText.length()-1)));
463524
gtk_entry_completion_complete(completion);
464525

465-
if(oldText.length() == 0) return;
526+
//Setting min key length to either 0 or 1 less than key length (max option)
527+
gtk_entry_completion_set_minimum_key_length(completion, std::max(0, (int)(oldText.length() - 1)));
466528

529+
//If string len is 0, reutrning
530+
if (oldText.length() == 0) return;
467531

468-
std::cout << "Added text" << std::endl;
469532
gtk_widget_grab_focus(GTK_WIDGET(searchBar));
470-
std::string newText = (oldText.length() > 1)? oldText.substr(0, oldText.length()-1) : "";
533+
std::string newText = (oldText.length() > 1) ? oldText.substr(0, oldText.length() - 1) : "";
471534
gtk_entry_set_text(searchBar, newText.c_str());
472-
// for(int i = 0; i < oldText.length(); ++i){
473-
474-
GdkEvent new_event;
475-
new_event.key.type = GDK_KEY_PRESS;
476-
new_event.key.window = gtk_widget_get_parent_window(GTK_WIDGET(searchBar));
477-
new_event.key.send_event = TRUE;
478-
new_event.key.time = GDK_CURRENT_TIME;
479-
new_event.key.keyval = gdk_unicode_to_keyval((int)oldText[oldText.length()-1]);
480-
new_event.key.state = GDK_KEY_PRESS_MASK;
481-
new_event.key.length = 0;
482-
new_event.key.string = 0;
483-
new_event.key.hardware_keycode = 0;
484-
new_event.key.group = 0;
485-
gdk_event_put(&new_event);
486-
//}
487-
}
488535

536+
//Creating a false event to insert the last character into the string
537+
auto window = gtk_widget_get_parent_window(GTK_WIDGET(searchBar));
538+
GdkEvent new_event = simulate_keypress(oldText.back(), window);
539+
gdk_event_put(&new_event);
540+
}
489541

490-
std::string get_search_type(ezgl::application* app){
542+
std::string get_search_type(ezgl::application* app) {
491543
GObject* combo_box = (GObject*)app->get_object("SearchType");
492544
gchar* type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box));
493545
//Checking that a type is selected

0 commit comments

Comments
 (0)