Skip to content

Commit 7eb7c4c

Browse files
simplify the logic in draw_place and add a doxygen comment
1 parent b3627f5 commit 7eb7c4c

File tree

3 files changed

+81
-94
lines changed

3 files changed

+81
-94
lines changed

vpr/src/draw/draw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ static void draw_main_canvas(ezgl::renderer* g) {
180180
g->set_font_size(14);
181181
if (draw_state->pic_on_screen != e_pic_type::ANALYTICAL_PLACEMENT) {
182182
draw_block_pin_util();
183-
drawplace(g);
183+
draw_place(g);
184184
draw_internal_draw_subblk(g);
185185

186186
draw_interposer_cuts(g);
187187

188188
draw_block_pin_util();
189-
drawplace(g);
189+
draw_place(g);
190190
draw_internal_draw_subblk(g);
191191

192192
if (draw_state->pic_on_screen == e_pic_type::ROUTING) { // ROUTING on screen

vpr/src/draw/draw_basic.cpp

Lines changed: 72 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ const std::vector<ezgl::color> kelly_max_contrast_colors = {
7070
ezgl::color(43, 61, 38) //olive green
7171
};
7272

73-
/* Draws the blocks placed on the proper clbs. Occupied blocks are darker colours *
74-
* while empty ones are lighter colours and have a dashed border. */
75-
void drawplace(ezgl::renderer* g) {
73+
void draw_place(ezgl::renderer* g) {
7674
t_draw_state* draw_state = get_draw_state_vars();
7775
t_draw_coords* draw_coords = get_draw_coords_vars();
7876
const DeviceContext& device_ctx = g_vpr_ctx.device();
@@ -84,96 +82,89 @@ void drawplace(ezgl::renderer* g) {
8482

8583
g->set_line_width(0);
8684
for (int layer_num = 0; layer_num < total_num_layers; layer_num++) {
87-
if (draw_state->draw_layer_display[layer_num].visible) {
88-
for (int i = 0; i < (int)grid.width(); i++) {
89-
for (int j = 0; j < (int)grid.height(); j++) {
90-
if (!grid.is_root_location({i, j, layer_num})) {
91-
continue;
92-
}
85+
if (!draw_state->draw_layer_display[layer_num].visible) {
86+
continue;
87+
}
88+
// The transparency level for the current layer being drawn (0-255)
89+
const int transparency_factor = draw_state->draw_layer_display[layer_num].alpha;
9390

94-
// Only the first block of a group should control drawing
95-
const t_physical_tile_type_ptr type = grid.get_physical_type({i, j, layer_num});
91+
for (int i = 0; i < (int)grid.width(); i++) {
92+
for (int j = 0; j < (int)grid.height(); j++) {
93+
if (!grid.is_root_location({i, j, layer_num})) {
94+
continue;
95+
}
9696

97-
//The transparency level for the current layer being drawn (0-255)
98-
// 0 - opaque, 255 - transparent
99-
int transparency_factor = draw_state->draw_layer_display[layer_num].alpha;
97+
// Only the first block of a group should control drawing
98+
const t_physical_tile_type_ptr type = grid.get_physical_type({i, j, layer_num});
10099

101-
int num_sub_tiles = type->capacity;
102-
/* Don't draw if tile capacity is zero. eg-> corners. */
103-
if (num_sub_tiles == 0) {
104-
continue;
105-
}
100+
int num_sub_tiles = type->capacity;
101+
// Don't draw if tile capacity is zero. eg-> corners.
102+
if (num_sub_tiles == 0) {
103+
continue;
104+
}
106105

107-
for (int k = 0; k < num_sub_tiles; ++k) {
108-
/* Look at the tile at start of large block */
109-
ClusterBlockId bnum = grid_blocks.block_at_location({i, j, k, layer_num});
110-
/* Fill background for the clb. Do not fill if "show_blk_internal"
111-
* is toggled.
112-
*/
113-
114-
//Determine the block color and logical type
115-
ezgl::color block_color;
116-
t_logical_block_type_ptr logical_block_type = nullptr;
117-
118-
//flag whether the current location is highlighted with a special color or not
119-
bool current_loc_is_highlighted = false;
120-
121-
if (placer_breakpoint_reached()) {
122-
t_pl_loc curr_loc;
123-
curr_loc.x = i;
124-
curr_loc.y = j;
125-
curr_loc.layer = layer_num;
126-
current_loc_is_highlighted = highlight_loc_with_specific_color(curr_loc,
127-
block_color);
128-
}
129-
// No color specified at this location; use the block color.
130-
if (!current_loc_is_highlighted) {
131-
if (bnum) {
132-
block_color = draw_state->block_color(bnum);
133-
} else {
134-
block_color = get_block_type_color(type);
135-
block_color = lighten_color(block_color,
136-
EMPTY_BLOCK_LIGHTEN_FACTOR);
137-
}
106+
for (int k = 0; k < num_sub_tiles; ++k) {
107+
// Look at the tile at start of large block
108+
ClusterBlockId bnum = grid_blocks.block_at_location({i, j, k, layer_num});
109+
// Fill background for the clb. Do not fill if "show_blk_internal" is toggled.
110+
111+
// Determine the block color and logical type
112+
ezgl::color block_color;
113+
t_logical_block_type_ptr logical_block_type = nullptr;
114+
// flag whether the current location is highlighted with a special color or not
115+
bool current_loc_is_highlighted = false;
116+
117+
if (placer_breakpoint_reached()) {
118+
t_pl_loc curr_loc;
119+
curr_loc.x = i;
120+
curr_loc.y = j;
121+
curr_loc.layer = layer_num;
122+
current_loc_is_highlighted = highlight_loc_with_specific_color(curr_loc, block_color);
123+
}
124+
// No color specified at this location; use the block color.
125+
if (!current_loc_is_highlighted) {
126+
if (bnum) {
127+
block_color = draw_state->block_color(bnum);
128+
} else {
129+
block_color = get_block_type_color(type);
130+
block_color = lighten_color(block_color, EMPTY_BLOCK_LIGHTEN_FACTOR);
138131
}
132+
}
139133

140-
logical_block_type = pick_logical_type(type);
141-
g->set_color(block_color, transparency_factor);
134+
logical_block_type = pick_logical_type(type);
135+
g->set_color(block_color, transparency_factor);
142136

143-
/* Get coords of current sub_tile */
144-
ezgl::rectangle abs_clb_bbox = draw_coords->get_absolute_clb_bbox(layer_num,
145-
i,
146-
j,
147-
k,
148-
logical_block_type);
149-
ezgl::point2d center = abs_clb_bbox.center();
137+
// Get coords of current sub_tile
138+
ezgl::rectangle abs_clb_bbox = draw_coords->get_absolute_clb_bbox(layer_num,
139+
i,
140+
j,
141+
k,
142+
logical_block_type);
143+
ezgl::point2d center = abs_clb_bbox.center();
150144

151-
g->fill_rectangle(abs_clb_bbox);
145+
g->fill_rectangle(abs_clb_bbox);
152146

153-
g->set_color(ezgl::BLACK, transparency_factor);
147+
g->set_color(ezgl::BLACK, transparency_factor);
154148

155-
g->set_line_dash((bnum == ClusterBlockId::INVALID()) ? ezgl::line_dash::asymmetric_5_3 : ezgl::line_dash::none);
156-
if (draw_state->draw_block_outlines) {
157-
g->draw_rectangle(abs_clb_bbox);
158-
}
149+
g->set_line_dash((bnum == ClusterBlockId::INVALID()) ? ezgl::line_dash::asymmetric_5_3 : ezgl::line_dash::none);
150+
if (draw_state->draw_block_outlines) {
151+
g->draw_rectangle(abs_clb_bbox);
152+
}
159153

160-
if (draw_state->draw_block_text) {
161-
/* Draw text if the space has parts of the netlist */
162-
if (bnum) {
163-
std::string name = cluster_ctx.clb_nlist.block_name(bnum) + vtr::string_fmt(" (#%zu)", size_t(bnum));
164-
165-
g->draw_text(center, name.c_str(), abs_clb_bbox.width(),
166-
abs_clb_bbox.height());
167-
}
168-
/* Draw text for block type so that user knows what block */
169-
if (grid.is_root_location({i, j, layer_num})) {
170-
std::string block_type_loc = type->name;
171-
block_type_loc += vtr::string_fmt(" (%d,%d)", i, j);
172-
173-
g->draw_text(center - ezgl::point2d(0, abs_clb_bbox.height() / 4),
174-
block_type_loc.c_str(), abs_clb_bbox.width(), abs_clb_bbox.height());
175-
}
154+
if (draw_state->draw_block_text) {
155+
// Draw text if the space has parts of the netlist
156+
if (bnum) {
157+
std::string name = cluster_ctx.clb_nlist.block_name(bnum) + vtr::string_fmt(" (#%zu)", size_t(bnum));
158+
159+
g->draw_text(center, name.c_str(), abs_clb_bbox.width(), abs_clb_bbox.height());
176160
}
161+
162+
// Draw text for block type so that user knows what block
163+
std::string block_type_loc = type->name;
164+
block_type_loc += vtr::string_fmt(" (%d,%d)", i, j);
165+
166+
g->draw_text(center - ezgl::point2d(0, abs_clb_bbox.height() / 4),
167+
block_type_loc.c_str(), abs_clb_bbox.width(), abs_clb_bbox.height());
177168
}
178169
}
179170
}

vpr/src/draw/draw_basic.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#ifndef NO_GRAPHICS
1111

1212
#include <cstdio>
13-
#include <cfloat>
1413
#include <cstring>
15-
#include <cmath>
1614

1715
#include "draw_types.h"
1816
#include "netlist_fwd.h"
@@ -24,10 +22,13 @@
2422
#include "ezgl/point.hpp"
2523
#include "ezgl/graphics.hpp"
2624

27-
/* Draws the blocks placed on the proper clbs. Occupied blocks are darker colours *
28-
* while empty ones are lighter colours and have a dashed border. *
29-
* Blocks are drawn in layer order (so that semi-transparent blocks/grids render well)*/
30-
void drawplace(ezgl::renderer* g);
25+
/**
26+
* @brief Draws all placed blocks on the device grid across visible layers.
27+
*
28+
* Occupied blocks are darker colours while empty ones are lighter colours and have a dashed border.
29+
* Blocks are drawn in layer order (so that semi-transparent blocks/grids render well)
30+
*/
31+
void draw_place(ezgl::renderer* g);
3132

3233
/** This function draws the analytical placement from the PartialPlacement object, it
3334
* also draws the architecture grid and the blocks from device_ctx.
@@ -74,11 +75,6 @@ int get_timing_path_node_layer_num(tatum::NodeId node);
7475
* @brief Returns true if both the current_node and prev_node are on the same layer and it is visible,
7576
* or they're on different layers that are both visible and cross-layer connections are visible.
7677
* Otherwise returns false.
77-
*
78-
* @param current_node
79-
* @param prev_node
80-
*
81-
* @return
8278
*/
8379
bool is_edge_valid_to_draw(RRNodeId current_node, RRNodeId prev_node);
8480

0 commit comments

Comments
 (0)