Skip to content

Commit 031ae9a

Browse files
Made PR fixes. Added performance info for search.
1 parent d987df5 commit 031ae9a

File tree

5 files changed

+61
-37
lines changed

5 files changed

+61
-37
lines changed

vpr/src/draw/draw.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sstream>
2121
#include <array>
2222
#include <iostream>
23+
#include <time.h>
2324

2425
#include "vtr_assert.h"
2526
#include "vtr_ndoffsetmatrix.h"
@@ -669,21 +670,15 @@ bool draw_if_net_highlighted(ClusterNetId inet) {
669670
if (draw_state->net_color[inet] != DEFAULT_RR_NODE_COLOR) {
670671
return true;
671672
}
672-
673673
return false;
674674
}
675675

676-
# if defined(X11) && !defined(__MINGW32__)
677-
void act_on_key_press(ezgl::application* app, GdkEventKey* /*event*/, char* key_name) {
678-
//VTR_LOG("Key press %c (%d)\n", key_pressed, keysym);
679-
std::string key(key_name);
680-
if (gtk_widget_is_focus(GTK_WIDGET(app->get_object("TextInput")))) {
681-
if (key == "Return") {
682-
enable_autocomplete(app);
683-
}
684-
}
685-
}
686-
# else
676+
/**
677+
* @brief cbk function for key press
678+
*
679+
* At the moment, only does something if user is currently typing in searchBar and
680+
* hits enter, at which point it runs autocomplete
681+
*/
687682
void act_on_key_press(ezgl::application* app, GdkEventKey* /*event*/, char* key_name) {
688683
std::string key(key_name);
689684
GtkWidget* searchBar = GTK_WIDGET(app->get_object("TextInput"));
@@ -695,7 +690,6 @@ void act_on_key_press(ezgl::application* app, GdkEventKey* /*event*/, char* key_
695690
}
696691
}
697692
}
698-
# endif
699693

700694
void act_on_mouse_press(ezgl::application* app, GdkEventButton* event, double x, double y) {
701695
// std::cout << "User clicked the ";

vpr/src/draw/draw_toggle_functions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,12 @@ void toggle_expansion_cost_cbk(GtkComboBoxText* self, ezgl::application* app) {
409409
/**
410410
* @brief cbk fn to toggle Network-On-Chip (Noc) visibility
411411
* alters draw_state->draw_noc to reflect new state
412+
* Reacts to main.ui created combo box, setup in ui_setup.cpp
412413
*
413414
* @param self ptr to combo box
414415
* @param app ezgl application
415416
*/
416417
void toggle_noc_cbk(GtkComboBoxText* self, ezgl::application* app) {
417-
/* this is the callback function for runtime created toggle_noc_display button
418-
* which is written in button.cpp */
419418
t_draw_state* draw_state = get_draw_state_vars();
420419

421420
gchar* combo_box_content = gtk_combo_box_text_get_active_text(self);

vpr/src/draw/search_bar.cpp

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void search_and_highlight(GtkWidget* /*widget*/, ezgl::application* app) {
7575
std::stringstream ss(user_input);
7676

7777
auto search_type = get_search_type(app);
78+
if (search_type == "")
79+
return;
7880

7981
// reset
8082
deselect_all();
@@ -121,22 +123,22 @@ void search_and_highlight(GtkWidget* /*widget*/, ezgl::application* app) {
121123

122124
AtomBlockId atom_blk_id = atom_ctx.nlist.find_block(block_name);
123125
if (atom_blk_id != AtomBlockId::INVALID()) {
124-
ClusterBlockId block_id = atom_ctx.lookup.atom_clb(atom_blk_id);
125-
if (!highlight_atom_block(atom_blk_id, block_id, app)) {
126-
highlight_cluster_block(block_id);
126+
ClusterBlockId cluster_block_id = atom_ctx.lookup.atom_clb(atom_blk_id);
127+
if (!highlight_atom_block(atom_blk_id, cluster_block_id, app)) {
128+
highlight_cluster_block(cluster_block_id);
127129
}
128130
return;
129131
}
130132

131133
//Continues if atom block not found (Checking if user searched a clb)
132-
ClusterBlockId block_id = ClusterBlockId::INVALID();
133-
block_id = cluster_ctx.clb_nlist.find_block(block_name);
134+
ClusterBlockId cluster_block_id = ClusterBlockId::INVALID();
135+
cluster_block_id = cluster_ctx.clb_nlist.find_block(block_name);
134136

135-
if (block_id == ClusterBlockId::INVALID()) {
137+
if (cluster_block_id == ClusterBlockId::INVALID()) {
136138
warning_dialog_box("Invalid Block Name");
137139
return; //name not exist
138140
}
139-
highlight_cluster_block(block_id); //found block
141+
highlight_cluster_block(cluster_block_id); //found block
140142
}
141143

142144
else if (search_type == "Net ID") {
@@ -340,10 +342,11 @@ bool highlight_atom_block(AtomBlockId atom_blk, ClusterBlockId cl_blk, ezgl::app
340342
t_pb* find_atom_block_in_pb(std::string name, t_pb* pb) {
341343
//Checking if block is one being searched for
342344
std::string pbName(pb->name);
343-
if (pbName == name) return pb;
345+
if (pbName == name)
346+
return pb;
344347
//If block has no children, returning
345-
if (pb->child_pbs == nullptr) return nullptr;
346-
348+
if (pb->child_pbs == nullptr)
349+
return nullptr;
347350
int num_child_types = pb->get_num_child_types();
348351
//Iterating through all child types
349352
for (int i = 0; i < num_child_types; ++i) {
@@ -373,10 +376,7 @@ void highlight_nets(ClusterNetId net_id) {
373376

374377
//If routing does not exist return
375378
if (int(route_ctx.trace.size()) == 0) return;
376-
377-
for (tptr = route_ctx.trace[net_id].head; tptr != nullptr; tptr = tptr->next) {
378-
draw_state->net_color[net_id] = ezgl::MAGENTA;
379-
}
379+
draw_state->net_color[net_id] = ezgl::MAGENTA;
380380
}
381381

382382
void warning_dialog_box(const char* message) {
@@ -445,13 +445,14 @@ void search_type_changed(GtkComboBox* self, ezgl::application* app) {
445445

446446
/**
447447
* @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.
448+
* searches string for presence of a substring. Case-insensitive
449449
*
450450
* @param completer the GtkEntryCompletion being used
451451
* @param key a normalized and case-folded key representing the text
452452
* @param iter GtkTreeIter pointing at the current entry being compared
453453
* @param user_data null
454-
* @return gboolean
454+
* @return true | if the string pointed to by iter contains key (case-insensitive)
455+
* @return false | if the string pointed to does not contain key
455456
*/
456457
gboolean customMatchingFunction(
457458
GtkEntryCompletion* completer,
@@ -471,7 +472,8 @@ gboolean customMatchingFunction(
471472
}
472473

473474
/**
474-
* @brief Creates a GdkEvent that simulates user pressing key "key"
475+
* @brief Creates a GdkEvent that simulates user pressing key "key".
476+
* Currently used to fool GtkEntryCompletion into showing options w/o receiving a new input
475477
*
476478
* @param key character value
477479
* @param window GdkWindow
@@ -502,13 +504,36 @@ GdkEvent simulate_keypress(char key, GdkWindow* window) {
502504
* as the user hits the "Enter" key. To accomplish this, a fake Gdk event is created
503505
* to simulate the user hitting a key.
504506
*
507+
* This was done for usability reasons; if this is not done, user will need to input another key before seeing
508+
* autocomplete results. Considering the enter is supposed to be a search, we want to search for the users
509+
* key, not the key + another char
510+
*
511+
* PERFORMANCE DATA
512+
* Correlation between key length and time is shaky; there might be some correlation to
513+
* how many strings are similar to it. All tests are performed with the key "1" - pretty common
514+
* Tests are searched three times then average
515+
* MODEL 1: EARCH + TSENG.BLIF
516+
* NETS 1483
517+
* NET SRCH. 19392
518+
* BLOCKS 1835
519+
* BLOCK SRCH. 21840
520+
* For second model (much larger, much longer CPU times) observed large dropoff in times from one char to two chars (about 2 times faster) but after stayed consistent
521+
* Maybe when I ahve more time, will make a cute graph or something, no time right now
522+
* MODEL 2: Strativix arch + MES_NOC (TITAN)
523+
* NETS 577696
524+
* NET SRCH. 4.93438e+06
525+
* BLOCKS 572148
526+
* BLOCKS SRCH. 4.8654e+06
527+
* Obviously much slower w. more nets/blocks. However, it only performs a single search, pretty bearable considering its searching in strings
505528
* @param app ezgl app
506529
*/
507530
void enable_autocomplete(ezgl::application* app) {
508531
GtkEntryCompletion* completion = GTK_ENTRY_COMPLETION(app->get_object("Completion"));
509532
GtkEntry* searchBar = GTK_ENTRY(app->get_object("TextInput"));
510533

511534
std::string searchType = get_search_type(app);
535+
if (searchType == "")
536+
return;
512537
//Checking to make sure that we are on a mode that uses auto-complete
513538
if (gtk_entry_completion_get_model(completion) == NULL) {
514539
std::cout << "NO MODEL SELECTED" << std::endl;
@@ -538,14 +563,15 @@ void enable_autocomplete(ezgl::application* app) {
538563
gdk_event_put(&new_event);
539564
}
540565

566+
//Returns current search type. Returns empty string if fails
541567
std::string get_search_type(ezgl::application* app) {
542568
GObject* combo_box = (GObject*)app->get_object("SearchType");
543569
gchar* type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box));
544570
//Checking that a type is selected
545-
if (type && type[0] == '\0') {
571+
if (!type || (type && type[0] == '\0')) {
546572
warning_dialog_box("Please select a search type");
547573
app->refresh_drawing();
548-
return "Failed lol";
574+
return "";
549575
}
550576
std::string searchType(type);
551577
return searchType;

vpr/src/draw/search_bar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool highlight_atom_block(AtomBlockId atom_blk, ClusterBlockId cl_blk, ezgl::app
4040
//Turns on autocomplete/suggestions
4141
void enable_autocomplete(ezgl::application* app);
4242

43-
//Simulates key press event
43+
//Simulates key press event
4444
GdkEvent simulate_keypress(char key, GdkWindow* window);
4545

4646
//Returns current search type

vpr/src/draw/ui_setup.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void hide_widget(std::string widgetName, ezgl::application* app) {
192192
}
193193

194194
/**
195-
* @brief loads block names into gtk list store item used for completion
195+
* @brief loads atom and cluster lvl names into gtk list store item used for completion
196196
*
197197
* @param app ezgl application used for ui
198198
*/
@@ -201,20 +201,23 @@ void load_block_names(ezgl::application* app) {
201201
auto& cluster_ctx = g_vpr_ctx.clustering();
202202
auto& atom_ctx = g_vpr_ctx.atom();
203203
GtkTreeIter iter;
204+
int i = 0;
204205
for (ClusterBlockId id : cluster_ctx.clb_nlist.blocks()) {
205206
gtk_list_store_append(blockStorage, &iter);
206207
gtk_list_store_set(blockStorage, &iter,
207208
0, (cluster_ctx.clb_nlist.block_name(id)).c_str(), -1);
209+
i++;
208210
}
209211
for (AtomBlockId id : atom_ctx.nlist.blocks()) {
210212
gtk_list_store_append(blockStorage, &iter);
211213
gtk_list_store_set(blockStorage, &iter,
212214
0, (atom_ctx.nlist.block_name(id)).c_str(), -1);
215+
i++;
213216
}
214217
}
215218

216219
/**
217-
* @brief loads net names into gtk list store item used for completion
220+
* @brief loads atom net names into gtk list store item used for completion
218221
*
219222
* @param app ezgl application used for ui
220223
*/
@@ -223,10 +226,12 @@ void load_net_names(ezgl::application* app) {
223226
auto& atom_ctx = g_vpr_ctx.atom();
224227
GtkTreeIter iter;
225228
//Loading net names
229+
int i = 0;
226230
for (AtomNetId id : atom_ctx.nlist.nets()) {
227231
gtk_list_store_append(netStorage, &iter);
228232
gtk_list_store_set(netStorage, &iter,
229233
0, (atom_ctx.nlist.net_name(id)).c_str(), -1);
234+
i++;
230235
}
231236
}
232237

0 commit comments

Comments
 (0)