diff options
Diffstat (limited to 'ui.c')
| -rw-r--r-- | ui.c | 67 |
1 files changed, 67 insertions, 0 deletions
@@ -12,6 +12,8 @@ #include "engine.h" #include "ui.h" #include "eprintf.h" +#include "color.h" +#include "util.h" #define DEFAULT_DISPLACEMENT (litre(1.5)) @@ -24,6 +26,10 @@ #define DEFAULT_INTERCOOLER_EFFICIENCY (percent(90)) #define DEFAULT_INTERCOOLER_DELTAP (psi(0.2)) +enum { POINT_RADIUS = 6 }; + +static const mu_Color POINT_COLOR = RED; + static void init_displacement(UI *ui); static void init_ambient_temperature(UI *ui); @@ -48,6 +54,10 @@ static void compute_manifold_temperature(UI *ui, int idx); static void compute_volume_flow_rate(UI *ui, int idx); static void compute_mass_flow_rate(UI *ui, int idx); static void compute_mass_flow_rate_corrected(UI *ui, int idx); +static void draw_points(UI *ui); +static void draw_point(UI *ui, int idx, mu_Color color); +static void point_coords(UI *ui, int idx, int *x, int *y); +static const Compressor *selected_compressor(UI *ui); /* Returns non-zero on error. The renderer must already be initialized. */ @@ -433,6 +443,8 @@ compute(UI *ui, int idx) { compute_volume_flow_rate(ui, idx); compute_mass_flow_rate(ui, idx); compute_mass_flow_rate_corrected(ui, idx); + + draw_points(ui); } void @@ -522,6 +534,61 @@ compute_mass_flow_rate_corrected(UI *ui, int idx) { w_set_number(ui->mass_flow_rate_corrected[idx], v); } +static void +draw_points(UI *ui) { + int i; + + w_clear_canvas(&ui->comp_img); + #pragma omp parallel for + for (i = 0; i < ui->npoints; i++) { + draw_point(ui, i, POINT_COLOR); + } +} + +static void +draw_point(UI *ui, int idx, mu_Color color) { + int x, y; + + point_coords(ui, idx, &x, &y); + w_canvas_draw_circle(&ui->comp_img, x, y, POINT_RADIUS, color); +} + +static void +point_coords(UI *ui, int idx, int *x, int *y) { + const Compressor *comp; + const Engine *engine; + double flow, origin_flow, ref_flow, r, pr; + + comp = selected_compressor(ui); + engine = &ui->points[idx]; + + expect(comp->origin.flow.t == comp->ref.flow.t); + switch (comp->origin.flow.t) { + case MASS_FLOW: + flow = mass_flow_rate_corrected(engine); + origin_flow = comp->origin.flow.u.mfr; + ref_flow = comp->ref.flow.u.mfr; + break; case VOLUME_FLOW: + flow = volume_flow_rate(engine); + origin_flow = comp->origin.flow.u.vfr; + ref_flow = comp->ref.flow.u.vfr; + break; default: + eprintf("impossible FlowType: %d", comp->origin.flow.t); + } + + r = (flow - origin_flow) / (ref_flow - origin_flow); + *x = comp->origin.x + r * (comp->ref.x - comp->origin.x); + + pr = pressure_ratio(engine); + r = (pr - comp->origin.pr) / (comp->ref.pr - comp->origin.pr); + *y = comp->origin.y + r * (comp->ref.y - comp->origin.y); +} + +static const Compressor * +selected_compressor(UI *ui) { + return &ui->comps[ui->comp_select.idx]; +} + void insert_point(UI *ui, int idx) { int i; |