static int editsource_exec(bContext *C, wmOperator *op) { uiBut *but = UI_context_active_but_get(C); if (but) { GHashIterator ghi; struct uiEditSourceButStore *but_store = NULL; ARegion *ar = CTX_wm_region(C); int ret; /* needed else the active button does not get tested */ UI_screen_free_active_but(C, CTX_wm_screen(C)); // printf("%s: begin\n", __func__); /* take care not to return before calling ui_editsource_active_but_clear */ ui_editsource_active_but_set(but); /* redraw and get active button python info */ ED_region_do_layout(C, ar); ED_region_do_draw(C, ar); ar->do_draw = false; for (BLI_ghashIterator_init(&ghi, ui_editsource_info->hash); BLI_ghashIterator_done(&ghi) == false; BLI_ghashIterator_step(&ghi)) { uiBut *but_key = BLI_ghashIterator_getKey(&ghi); if (but_key && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but_key)) { but_store = BLI_ghashIterator_getValue(&ghi); break; } } if (but_store) { if (but_store->py_dbg_ln != -1) { ret = editsource_text_edit(C, op, but_store->py_dbg_fn, but_store->py_dbg_ln); } else { BKE_report( op->reports, RPT_ERROR, "Active button is not from a script, cannot edit source"); ret = OPERATOR_CANCELLED; } } else { BKE_report(op->reports, RPT_ERROR, "Active button match cannot be found"); ret = OPERATOR_CANCELLED; } ui_editsource_active_but_clear(); // printf("%s: end\n", __func__); return ret; } else { BKE_report(op->reports, RPT_ERROR, "Active button not found"); return OPERATOR_CANCELLED; } }
void BKE_sim_debug_data_clear_category(const char *category) { int category_hash = (int)BLI_ghashutil_strhash_p(category); if (!_sim_debug_data) return; if (_sim_debug_data->gh) { GHashIterator iter; BLI_ghashIterator_init(&iter, _sim_debug_data->gh); while (!BLI_ghashIterator_done(&iter)) { const SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); BLI_ghashIterator_step(&iter); /* removing invalidates the current iterator, so step before removing */ if (elem->category_hash == category_hash) BLI_ghash_remove(_sim_debug_data->gh, elem, NULL, debug_element_free); } } }
static void draw_sim_debug_elements(SimDebugData *debug_data, float imat[4][4]) { GHashIterator iter; /**** dots ****/ glPointSize(3.0f); glBegin(GL_POINTS); for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); if (elem->type != SIM_DEBUG_ELEM_DOT) continue; glColor3f(elem->color[0], elem->color[1], elem->color[2]); glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]); } glEnd(); /**** circles ****/ { float circle[16][2] = { {0.000000, 1.000000}, {0.382683, 0.923880}, {0.707107, 0.707107}, {0.923880, 0.382683}, {1.000000, -0.000000}, {0.923880, -0.382683}, {0.707107, -0.707107}, {0.382683, -0.923880}, {-0.000000, -1.000000}, {-0.382683, -0.923880}, {-0.707107, -0.707107}, {-0.923879, -0.382684}, {-1.000000, 0.000000}, {-0.923879, 0.382684}, {-0.707107, 0.707107}, {-0.382683, 0.923880} }; for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); float radius = elem->v2[0]; float co[3]; int i; if (elem->type != SIM_DEBUG_ELEM_CIRCLE) continue; glColor3f(elem->color[0], elem->color[1], elem->color[2]); glBegin(GL_LINE_LOOP); for (i = 0; i < 16; ++i) { co[0] = radius * circle[i][0]; co[1] = radius * circle[i][1]; co[2] = 0.0f; mul_mat3_m4_v3(imat, co); add_v3_v3(co, elem->v1); glVertex3f(co[0], co[1], co[2]); } glEnd(); } } /**** lines ****/ glBegin(GL_LINES); for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); if (elem->type != SIM_DEBUG_ELEM_LINE) continue; glColor3f(elem->color[0], elem->color[1], elem->color[2]); glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]); glVertex3f(elem->v2[0], elem->v2[1], elem->v2[2]); } glEnd(); /**** vectors ****/ glPointSize(2.0f); glBegin(GL_POINTS); for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); if (elem->type != SIM_DEBUG_ELEM_VECTOR) continue; glColor3f(elem->color[0], elem->color[1], elem->color[2]); glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]); } glEnd(); glBegin(GL_LINES); for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); float t[3]; if (elem->type != SIM_DEBUG_ELEM_VECTOR) continue; glColor3f(elem->color[0], elem->color[1], elem->color[2]); glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]); add_v3_v3v3(t, elem->v1, elem->v2); glVertex3f(t[0], t[1], t[2]); } glEnd(); /**** strings ****/ for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); if (elem->type != SIM_DEBUG_ELEM_STRING) continue; unsigned char col[4]; rgb_float_to_uchar(col, elem->color); col[3] = 255; view3d_cached_text_draw_add(elem->v1, elem->str, strlen(elem->str), 0, V3D_CACHE_TEXT_GLOBALSPACE, col); } }