Compare commits

..

No commits in common. "68e7d52cd8d0e32f0697ac7f81524a31a59b1282" and "845da756b72ffeec10497f2a164551ed1c7684be" have entirely different histories.

5 changed files with 32 additions and 108 deletions

View File

@ -113,7 +113,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">6</property> <property name="position">6</property>
</packing> </packing>
@ -151,38 +151,5 @@
<property name="position">7</property> <property name="position">7</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="x-output-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="y-output-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">8</property>
</packing>
</child>
</object> </object>
</interface> </interface>

View File

@ -250,14 +250,13 @@ static void on_convert_clicked(gpointer button, gpointer user)
bounding_box_prepare_empty(&cell_box); bounding_box_prepare_empty(&cell_box);
calculate_cell_bounding_box(&cell_box, cell_to_render); calculate_cell_bounding_box(&cell_box, cell_to_render);
/* Calculate size in meters database units */ /* Calculate size in meters */
height = (cell_box.vectors.upper_right.y - cell_box.vectors.lower_left.y); height = (cell_box.vectors.upper_right.y - cell_box.vectors.lower_left.y) * cell_to_render->parent_library->unit_in_meters;
width = (cell_box.vectors.upper_right.x - cell_box.vectors.lower_left.x); width = (cell_box.vectors.upper_right.x - cell_box.vectors.lower_left.x) * cell_to_render->parent_library->unit_in_meters;
/* Show settings dialog */ /* Show settings dialog */
settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window)); settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window));
renderer_settings_dialog_set_settings(settings, &sett); renderer_settings_dialog_set_settings(settings, &sett);
renderer_settings_dialog_set_database_unit_scale(settings, cell_to_render->parent_library->unit_in_meters);
renderer_settings_dialog_set_cell_height(settings, height); renderer_settings_dialog_set_cell_height(settings, height);
renderer_settings_dialog_set_cell_width(settings, width); renderer_settings_dialog_set_cell_width(settings, width);

View File

@ -165,10 +165,11 @@ void bounding_box_update_point(union bounding_box *destination, conv_generic_to_
{ {
struct vector_2d point; struct vector_2d point;
if (!destination || !pt) if (!destination || !pt) {
return; return;
}
if (conv_func) if (!conv_func)
conv_func(pt, &point); conv_func(pt, &point);
else else
(void)vector_2d_copy(&point, (struct vector_2d *)pt); (void)vector_2d_copy(&point, (struct vector_2d *)pt);

View File

@ -43,12 +43,8 @@ struct _RendererSettingsDialog {
GtkLabel *x_label; GtkLabel *x_label;
GtkLabel *y_label; GtkLabel *y_label;
GtkLabel *x_output_label; double cell_height;
GtkLabel *y_output_label; double cell_width;
unsigned int cell_height;
unsigned int cell_width;
double unit_in_meters;
}; };
G_DEFINE_TYPE(RendererSettingsDialog, renderer_settings_dialog, GTK_TYPE_DIALOG) G_DEFINE_TYPE(RendererSettingsDialog, renderer_settings_dialog, GTK_TYPE_DIALOG)
@ -114,13 +110,13 @@ static gboolean shape_drawer_drawing_callback(GtkWidget *widget, cairo_t *cr, gp
usable_width = (0.95*(double)width) - 15.0; usable_width = (0.95*(double)width) - 15.0;
usable_height = (0.95*(double)height) - 15.0; usable_height = (0.95*(double)height) - 15.0;
width_scale = usable_width/(double)dialog->cell_width; width_scale = usable_width/dialog->cell_width;
height_scale = usable_height/(double)dialog->cell_height; height_scale = usable_height/dialog->cell_height;
final_scale_value = (width_scale < height_scale ? width_scale : height_scale); final_scale_value = (width_scale < height_scale ? width_scale : height_scale);
cairo_rectangle(cr, -(double)dialog->cell_width*final_scale_value/2.0, -(double)dialog->cell_height*final_scale_value/2.0, cairo_rectangle(cr, -dialog->cell_width*final_scale_value/2, -dialog->cell_height*final_scale_value/2,
(double)dialog->cell_width*final_scale_value, (double)dialog->cell_height*final_scale_value); dialog->cell_width*final_scale_value, dialog->cell_height*final_scale_value);
cairo_stroke(cr); cairo_stroke(cr);
cairo_restore(cr); cairo_restore(cr);
@ -130,31 +126,11 @@ static gboolean shape_drawer_drawing_callback(GtkWidget *widget, cairo_t *cr, gp
static void renderer_settings_dialog_update_labels(RendererSettingsDialog *self) static void renderer_settings_dialog_update_labels(RendererSettingsDialog *self)
{ {
char default_buff[100]; char default_buff[100];
double scale;
if (!self) snprintf(default_buff, sizeof(default_buff), "Width: %E", self->cell_width);
return;
snprintf(default_buff, sizeof(default_buff), "Width: %E", self->cell_width * self->unit_in_meters);
gtk_label_set_text(self->x_label, default_buff); gtk_label_set_text(self->x_label, default_buff);
snprintf(default_buff, sizeof(default_buff), "Height: %E", self->cell_height * self->unit_in_meters); snprintf(default_buff, sizeof(default_buff), "Height: %E", self->cell_height);
gtk_label_set_text(self->y_label, default_buff); gtk_label_set_text(self->y_label, default_buff);
scale = gtk_range_get_value(GTK_RANGE(self->scale));
snprintf(default_buff, sizeof(default_buff), "Output Width: %u px", (unsigned int)((double)self->cell_width / scale));
gtk_label_set_text(self->x_output_label, default_buff);
snprintf(default_buff, sizeof(default_buff), "Output Height: %u px", (unsigned int)((double)self->cell_height / scale));
gtk_label_set_text(self->y_output_label, default_buff);
}
static void scale_value_changed(GtkRange *range, gpointer user_data)
{
(void)range;
RendererSettingsDialog *dialog;
dialog = RENDERER_SETTINGS_DIALOG(user_data);
renderer_settings_dialog_update_labels(dialog);
} }
static void renderer_settings_dialog_init(RendererSettingsDialog *self) static void renderer_settings_dialog_init(RendererSettingsDialog *self)
@ -176,8 +152,6 @@ static void renderer_settings_dialog_init(RendererSettingsDialog *self)
self->shape_drawing = GTK_DRAWING_AREA(gtk_builder_get_object(builder, "shape-drawer")); self->shape_drawing = GTK_DRAWING_AREA(gtk_builder_get_object(builder, "shape-drawer"));
self->x_label = GTK_LABEL(gtk_builder_get_object(builder, "x-label")); self->x_label = GTK_LABEL(gtk_builder_get_object(builder, "x-label"));
self->y_label = GTK_LABEL(gtk_builder_get_object(builder, "y-label")); self->y_label = GTK_LABEL(gtk_builder_get_object(builder, "y-label"));
self->x_output_label = GTK_LABEL(gtk_builder_get_object(builder, "x-output-label"));
self->y_output_label = GTK_LABEL(gtk_builder_get_object(builder, "y-output-label"));
gtk_dialog_add_buttons(dialog, "Cancel", GTK_RESPONSE_CANCEL, "OK", GTK_RESPONSE_OK, NULL); gtk_dialog_add_buttons(dialog, "Cancel", GTK_RESPONSE_CANCEL, "OK", GTK_RESPONSE_OK, NULL);
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box);
@ -187,12 +161,9 @@ static void renderer_settings_dialog_init(RendererSettingsDialog *self)
g_signal_connect(G_OBJECT(self->shape_drawing), g_signal_connect(G_OBJECT(self->shape_drawing),
"draw", G_CALLBACK(shape_drawer_drawing_callback), (gpointer)self); "draw", G_CALLBACK(shape_drawer_drawing_callback), (gpointer)self);
g_signal_connect(self->scale, "value-changed", G_CALLBACK(scale_value_changed), (gpointer)self);
/* Default values */ /* Default values */
self->cell_width = 1; self->cell_width = 1E-6;
self->cell_height = 1; self->cell_height = 1E-6;
self->unit_in_meters = 1E-6;
renderer_settings_dialog_update_labels(self); renderer_settings_dialog_update_labels(self);
g_object_unref(builder); g_object_unref(builder);
@ -257,41 +228,34 @@ void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struc
} }
} }
void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, unsigned int width) void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, double width)
{ {
if (!dialog) if (!dialog)
return; return;
if (width == 0) if (width == 0.0)
width = 1; width = 1E-6;
if (width < 0.0)
width = -width;
dialog->cell_width = width; dialog->cell_width = width;
renderer_settings_dialog_update_labels(dialog); renderer_settings_dialog_update_labels(dialog);
} }
void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, unsigned int height) void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, double height)
{ {
if (!dialog) if (!dialog)
return; return;
if (height == 0) if (height == 0.0)
height = 1; height = 1E-6;
if (height < 0.0)
height = -height;
dialog->cell_height = height; dialog->cell_height = height;
renderer_settings_dialog_update_labels(dialog); renderer_settings_dialog_update_labels(dialog);
} }
void renderer_settings_dialog_set_database_unit_scale(RendererSettingsDialog *dialog, double unit_in_meters)
{
if (!dialog)
return;
if (unit_in_meters < 0)
unit_in_meters *= -1;
dialog->unit_in_meters = unit_in_meters;
renderer_settings_dialog_update_labels(dialog);
}
/** @} */ /** @} */

View File

@ -78,23 +78,16 @@ void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struc
/** /**
* @brief renderer_settings_dialog_set_cell_width Set width for rendered cell * @brief renderer_settings_dialog_set_cell_width Set width for rendered cell
* @param dialog * @param dialog
* @param width Width in database units * @param width Width in meters
*/ */
void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, unsigned int width); void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, double width);
/** /**
* @brief renderer_settings_dialog_set_cell_height Set height for rendered cell * @brief renderer_settings_dialog_set_cell_height Set height for rendered cell
* @param dialog * @param dialog
* @param height Height in database units * @param height Height in meters
*/ */
void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, unsigned int height); void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, double height);
/**
* @brief renderer_settings_dialog_set_database_unit_scale Set database scale
* @param dialog dialog element
* @param unit_in_meters Database unit in meters
*/
void renderer_settings_dialog_set_database_unit_scale(RendererSettingsDialog *dialog, double unit_in_meters);
#endif /* __CONV_SETTINGS_DIALOG_H__ */ #endif /* __CONV_SETTINGS_DIALOG_H__ */