Adds possibility to color marks in scatter plots
[scilab.git] / scilab / modules / graphics / src / c / getHandleProperty / SetHashTable.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
4  * Copyright (C) 2007 - INRIA - Vincent Couvert
5  *
6  * This file must be used under the terms of the CeCILL.
7  * This source file is licensed as described in the file COPYING, which
8  * you should have received as part of this distribution.  The terms
9  * are also available at
10  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
11  *
12  */
13
14 /*------------------------------------------------------------------------*/
15 /* file: SetHashTable.c                                                   */
16 /* desc : implementation of the scilab hashtable for the set procedure    */
17 /*------------------------------------------------------------------------*/
18 #include <string.h>
19 #include "SetHashTable.h"
20 #include "setHandleProperty.h"
21 #include "Scierror.h"
22 #include "localization.h"
23 #include "getDictionarySetProperties.h"
24 #include "MALLOC.h"
25 #include "BOOL.h"
26 #ifdef _MSC_VER
27 #include "strdup_windows.h"
28 #endif
29
30 /**
31 * use for the singleton to know if the hashtable has already be created.
32 */
33 static BOOL setHashTableCreated = FALSE;
34
35 /**
36 * the get hashtable
37 */
38 static SetPropertyHashTable *setHashTable = NULL;
39
40 /**
41 * a couple of key (property name) and associated value
42 * (accessor name)
43 */
44 typedef struct
45 {
46     char *key;
47     setPropertyFunc accessor;
48 } setHashTableCouple;
49
50 /**
51 * list of all property names and associated functions in scilab
52 * This is inserted in the hashTable
53 */
54 static setHashTableCouple propertySetTable[] =
55 {
56     {"visible", set_visible_property},
57     {"pixel_drawing_mode", set_pixel_drawing_mode_property},
58     {"old_style", set_old_style_property},
59     {"figure_style", set_figure_style_property},
60     {"auto_resize", set_auto_resize_property},
61     {"figure_position", set_figure_position_property},
62     {"axes_size", set_axes_size_property},
63     {"figure_size", set_figure_size_property},
64     {"figure_name", set_figure_name_property},
65     {"figure_id", set_figure_id_property},
66     {"rotation_style", set_rotation_style_property},
67     {"immediate_drawing", set_immediate_drawing_property},
68     {"parent", set_parent_property},
69     {"current_axes", set_current_axes_property},
70     {"current_figure", set_current_figure_property},
71     {"current_obj", set_current_entity_property},
72     {"current_entity", set_current_entity_property},
73     {"hdl", set_current_entity_property},
74     {"children", set_children_property},
75     {"default_values", set_default_values_property},
76     {"color_map", set_color_map_property},
77     {"interp_color_vector", set_interp_color_vector_property},
78     {"interp_color_mode", set_interp_color_mode_property},
79     {"background", set_background_property},
80     {"foreground", set_foreground_property},
81     {"fill_mode", set_fill_mode_property},
82     {"thickness", set_thickness_property},
83     {"arrow_size_factor", set_arrow_size_factor_property},
84     {"segs_color", set_segs_color_property},
85     {"line_style", set_line_style_property},
86     {"line_mode", set_line_mode_property},
87     {"surface_mode", set_surface_mode_property},
88     {"mark_style", set_mark_style_property},
89     {"mark_mode", set_mark_mode_property},
90     {"mark_size_unit", set_mark_size_unit_property},
91     {"mark_size", set_mark_size_property},
92     {"mark_foreground", set_mark_foreground_property},
93     {"mark_background", set_mark_background_property},
94     {"mark_offset", set_mark_offset_property},
95     {"mark_stride", set_mark_stride_property},
96     {"bar_layout", set_bar_layout_property},
97     {"bar_width", set_bar_width_property},
98     {"x_shift", set_x_shift_property},
99     {"y_shift", set_y_shift_property},
100     {"z_shift", set_z_shift_property},
101     {"polyline_style", set_polyline_style_property},
102     {"font_size", set_font_size_property},
103     {"font_angle", set_font_angle_property},
104     {"font_foreground", set_font_foreground_property},
105     {"font_color", set_font_color_property},
106     {"font_style", set_font_style_property},
107     {"text_box_mode", set_text_box_mode_property},
108     {"auto_dimensionning", set_auto_dimensionning_property},
109     {"alignment", set_alignment_property},
110     {"text_box", set_text_box_property},
111     {"text", set_text_property},
112     {"auto_clear", set_auto_clear_property},
113     {"auto_scale", set_auto_scale_property},
114     {"zoom_box", set_zoom_box_property},
115     {"zoom_state", set_zoom_state_property},
116     {"clip_box", set_clip_box_property},
117     {"clip_state", set_clip_state_property},
118     {"data", set_data_property},
119     {"callback", set_callback_property},
120     {"x_label", set_x_label_property},
121     {"y_label", set_y_label_property},
122     {"z_label", set_z_label_property},
123     {"title", set_title_property},
124     {"log_flags", set_log_flags_property},
125     {"tics_direction", set_tics_direction_property},
126     {"x_location", set_x_location_property},
127     {"y_location", set_y_location_property},
128     {"tight_limits", set_tight_limits_property},
129     {"closed", set_closed_property},
130     {"auto_position", set_auto_position_property},
131     {"auto_rotation", set_auto_rotation_property},
132     {"position", set_position_property},
133     {"auto_ticks", set_auto_ticks_property},
134     {"axes_reverse", set_axes_reverse_property},
135     {"view", set_view_property},
136     {"axes_bounds", set_axes_bounds_property},
137     {"data_bounds", set_data_bounds_property},
138     {"margins", set_margins_property},
139     {"auto_margins", set_auto_margins_property},
140     {"tics_color", set_tics_color_property},
141     {"tics_style", set_tics_style_property},
142     {"sub_tics", set_sub_tics_property},
143     {"sub_ticks", set_sub_tics_property},
144     {"tics_segment", set_tics_segment_property},
145     {"labels_font_size", set_labels_font_size_property},
146     {"labels_font_color", set_labels_font_color_property},
147     {"labels_font_style", set_labels_font_style_property},
148     {"format_n", set_format_n_property},
149     {"xtics_coord", set_xtics_coord_property},
150     {"ytics_coord", set_ytics_coord_property},
151     {"tics_labels", set_tics_labels_property},
152     {"box", set_box_property},
153     {"grid", set_grid_property},
154     {"grid_thickness", set_grid_thickness_property},
155     {"grid_style", set_grid_style_property},
156     {"axes_visible", set_axes_visible_property},
157     {"hiddencolor", set_hidden_color_property},
158     {"isoview", set_isoview_property},
159     {"cube_scaling", set_cube_scaling_property},
160     {"arrow_size", set_arrow_size_property},
161     {"colored", set_colored_property},
162     {"data_mapping", set_data_mapping_property},
163     {"rotation_angles", set_rotation_angles_property},
164     {"color_mode", set_color_mode_property},
165     {"color_flag", set_color_flag_property},
166     {"cdata_mapping", set_cdata_mapping_property},
167     {"surface_color", set_surface_color_property},
168     {"triangles", set_triangles_property},
169     {"z_bounds", set_z_bounds_property},
170     {"user_data", set_user_data_property},
171     {"userdata", set_user_data_property},   /* Compatibility with TK uicontrols */
172     {"handle_visible", set_handle_visible_property},
173     {"callback_type", set_callback_type_property},
174     {"enable", SetUiobjectEnable},
175     {"hidden_axis_color", set_hidden_axis_color_property},
176     {"x_ticks", set_x_ticks_property},
177     {"y_ticks", set_y_ticks_property},
178     {"z_ticks", set_z_ticks_property},
179     {"viewport", set_viewport_property},
180     {"info_message", set_info_message_property},
181     {"screen_position", set_screen_position_property},
182     {"event_handler_enable", set_event_handler_enable_property},
183     {"event_handler", set_event_handler_property},
184     {"label", SetUimenuLabel},
185     {"string", SetUicontrolString},
186     {"backgroundcolor", SetUicontrolBackgroundColor},
187     {"foregroundcolor", SetUiobjectForegroundColor},
188     {"fontweight", SetUicontrolFontWeight},
189     {"fontunits", SetUicontrolFontUnits},
190     {"fontsize", SetUicontrolFontSize},
191     {"fontangle", SetUicontrolFontAngle},
192     {"min", SetUicontrolMin},
193     {"max", SetUicontrolMax},
194     {"tag", set_tag_property},
195     {"listboxtop", SetUicontrolListboxTop},
196     {"value", SetUicontrolValue},
197     {"units", SetUicontrolUnits},
198     {"relief", SetUicontrolRelief},
199     {"horizontalalignment", SetUicontrolHorizontalAlignment},
200     {"verticalalignment", SetUicontrolVerticalAlignment},
201     {"fontname", SetUicontrolFontName},
202     {"sliderstep", SetUicontrolSliderStep},
203     {"checked", SetUimenuChecked},
204     {"arc_drawing_method", set_arc_drawing_method_property},
205     {"fractional_font", set_fractional_font_property},
206     {"links", set_links_property},
207     {"legend_location", set_legend_location_property},
208     {"filled", set_filled_property},
209     {"outside_colors", set_outside_colors_property},
210     {"color_range", set_color_range_property},
211     {"grid_position", set_grid_position_property},
212     {"anti_aliasing", set_anti_aliasing_property},
213     {"showhiddenhandles", SetConsoleShowHiddenHandles},
214     {"showhiddenproperties", SetConsoleShowHiddenProperties},
215     {"usedeprecatedskin", SetConsoleUseDeprecatedLF},
216     {"resizefcn", set_figure_resizefcn_property},
217     {"tooltipstring", SetUicontrolTooltipString},
218     {"closerequestfcn", set_figure_closerequestfcn_property},
219     {"orientation", set_tip_orientation_property},
220     {"z_component", set_tip_3component_property},
221     {"auto_orientation", set_tip_auto_orientation_property},
222     {"interp_mode", set_tip_interp_mode_property},
223     {"box_mode", set_tip_box_mode_property},
224     {"label_mode", set_tip_label_mode_property},
225     {"display_function", set_tip_disp_function_property},
226     {"ambient_color", set_ambient_color_property},
227     {"diffuse_color", set_diffuse_color_property},
228     {"specular_color", set_specular_color_property},
229     {"use_color_material", set_use_color_material_property},
230     {"material_shininess", set_material_shininess_property},
231     {"light_type", set_light_type_property},
232     {"direction", set_direction_property},
233     {"image_type", set_image_type_property},
234     {"datatips", set_datatips_property},
235     {"display_function_data", set_display_function_data_property},
236     {"resize", set_resize_property},
237     {"toolbar", set_toolbar_property},
238     {"toolbar_visible", set_toolbar_visible_property},
239     {"menubar", set_menubar_property},
240     {"menubar_visible", set_menubar_visible_property},
241     {"infobar_visible", set_infobar_visible_property},
242     {"dockable", set_dockable_property},
243     {"layout", set_layout_property},
244     {"constraints", set_constraints_property},
245     {"rect", set_rect_property},
246     {"layout_options", set_layout_options_property},
247     {"border", set_border_property},
248     {"groupname", set_groupname_property},
249     {"title_position", set_title_position_property},
250     {"title_scroll", set_title_scroll_property},
251     {"default_axes", set_default_axes_property},
252     {"scrollable", set_scrollable_property},
253     {"icon", SetUicontrolIcon},
254     {"line_width", set_line_width_property},
255     {"marks_count", set_marks_count_property},
256     {"ticks_format", set_ticks_format_property},
257     {"ticks_st", set_ticks_st_property},
258     {"colors", set_colors_property}
259 };
260
261 /*--------------------------------------------------------------------------*/
262 SetPropertyHashTable *createScilabSetHashTable(void)
263 {
264     int i = 0;
265
266     int propertyCount = sizeof(propertySetTable) / sizeof(setHashTableCouple);
267     if (setHashTableCreated)
268     {
269         return setHashTable;
270     }
271
272     /* create the hash table */
273     setHashTable = createSetHashTable();
274
275     if (setHashTable == NULL)
276     {
277         return NULL;
278     }
279
280     /* insert every couple */
281
282     for (i = 0; i < propertyCount ; i++)
283     {
284         insertSetHashtable(setHashTable, propertySetTable[i].key, propertySetTable[i].accessor);
285     }
286
287     setHashTableCreated = TRUE;
288
289     return setHashTable;
290
291 }
292
293 /*--------------------------------------------------------------------------*/
294 int callSetProperty(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol, char *propertyName)
295 {
296     setPropertyFunc accessor = searchSetHashtable(setHashTable, propertyName);
297
298     if (accessor == NULL)
299     {
300         Scierror(999, _("Unknown property: %s.\n"), propertyName);
301         return -1;
302     }
303     return accessor(_pvCtx, iObjUID, _pvData, valueType, nbRow, nbCol);
304 }
305
306 /*--------------------------------------------------------------------------*/
307 void destroyScilabSetHashTable(void)
308 {
309     if (!setHashTableCreated)
310     {
311         return;
312     }
313
314     destroySetHashTable(setHashTable);
315     setHashTableCreated = FALSE;
316 }
317
318 /*--------------------------------------------------------------------------*/
319 char **getDictionarySetProperties(int *sizearray)
320 {
321     char **dictionary = NULL;
322     int propertyCount = sizeof(propertySetTable) / sizeof(setHashTableCouple);
323
324     *sizearray = 0;
325     dictionary = (char **)MALLOC(sizeof(char *) * propertyCount);
326     if (dictionary)
327     {
328         int i = 0;
329
330         *sizearray = propertyCount;
331         for (i = 0; i < propertyCount ; i++)
332         {
333             dictionary[i] = strdup(propertySetTable[i].key);
334         }
335     }
336     return dictionary;
337 }
338
339 /*--------------------------------------------------------------------------*/
340 #undef NB_PROPERTIES