cuikmove_interface.c
Go to the documentation of this file.
1 
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <stdio.h>
17 #include <math.h>
18 
19 #include <gdk/gdkkeysyms.h>
20 #include <gtk/gtk.h>
21 
22 #include "cuikmove.h"
23 
24 #include "cuikmove_callbacks.h"
25 #include "cuikmove_interface.h"
26 #include "cuikplay_support.h"
27 
28 GtkWidget *create_window_cuikmove(gpointer status)
29 {
30  GtkWidget *window;
31  GtkWidget *table;
32  GtkWidget *hscale;
33  GtkWidget *Quit;
34  GtkWidget *Save;
35  GtkWidget *alignment;
36  GtkWidget *hbox;
37  GtkWidget *image;
38  GtkWidget *label;
40 
41  c=(TCuikMoveControl *)status;
42  unsigned int i;
43  char name[20];
44  char *string;
45  char *bstring;
46  double stepSize,pageSize;
47  unsigned int w,l,h,sh,k;
48  GdkScreen *screen;
49 
50  window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
51  w=0;
52  for(i=0;i<c->ndof;i++)
53  {
54  if (c->shown[i])
55  {
56  GetWorldDOFLabel(i,&string,c->w);
57  if (string!=NULL)
58  {
59  l=strlen(string);
60  if (l>w) w=l;
61  free(string);
62  }
63  }
64  }
65 
66  screen=gtk_window_get_screen(GTK_WINDOW(window));
67  sh=gdk_screen_get_height(screen);
68  if ((35+4)*(1+c->nShown)>sh)
69  h=(unsigned int)(floor((double)sh/(double)(1+c->nShown)))-4;
70  else
71  h=35;
72  gtk_widget_set_size_request(window,250+w*10,(h+4)*(1+c->nShown));
73  gtk_container_border_width (GTK_CONTAINER(window),3);
74  gtk_window_set_title(GTK_WINDOW(window),_("CuikMove"));
75  gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
76 
77  GLADE_HOOKUP_OBJECT_NO_REF(window,window,"window");
78 
79  g_signal_connect((gpointer)window, "destroy",
80  G_CALLBACK(on_cuikmove_quit),
81  status);
82 
83  table=gtk_table_new(c->nShown+1,2,FALSE);
84  gtk_widget_show(table);
85  gtk_container_add(GTK_CONTAINER(window),table);
86 
87  gtk_table_set_row_spacings(GTK_TABLE(table),2);
88  gtk_table_set_col_spacings(GTK_TABLE(table),2);
89 
90  stepSize=1.0/pow(10,(double)c->accuracy);
91 
92  /***********************************************************/
93  k=0;
94  for(i=0;i<c->ndof;i++)
95  {
96  GetWorldDOFLabel(i,&string,c->w);
97  //GetWorldJointLabel(i,&string,c->w);
98  if (c->shown[i]) /* DOF with ct range are not shown */
99  {
100  if (string!=NULL)
101  {
102  label=gtk_label_new(string);
103  NEW(bstring,strlen(string)+20,char);
104  sprintf(bstring,"<b>%s</b>",string);
105  gtk_label_set_markup(GTK_LABEL(label),bstring);
106  gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,k,k+1);
107  gtk_widget_show(label);
108 
109  free(bstring);
110  free(string);
111  }
112 
113  pageSize=0.01*(c->max[i]-c->min[i]);
114  hscale=gtk_hscale_new(GTK_ADJUSTMENT(gtk_adjustment_new(c->dof[i],c->min[i],
115  c->max[i],stepSize,
116  pageSize,10*stepSize)));
117 
118  gtk_widget_show(hscale);
119 
120  gtk_table_attach_defaults(GTK_TABLE(table),hscale,1,2,k,k+1);
121 
122  gtk_widget_set_size_request(hscale,250,h);
123  gtk_scale_set_draw_value(GTK_SCALE(hscale),TRUE);
124  gtk_scale_set_digits(GTK_SCALE(hscale),c->accuracy);
125 
126  sprintf(name,"S%u",i); /* keep 'i' to have the id of the true dof */
127  gtk_widget_set_name(hscale,name);
128 
129  g_signal_connect((gpointer)hscale,"value_changed",
130  G_CALLBACK(on_cuikmove_slider_changed),
131  status);
132 
133  GLADE_HOOKUP_OBJECT(window,hscale,name);
134  k++;
135  }
136  }
137 
138  /***********************************************************/
139 
140  Save=gtk_button_new();
141  gtk_widget_show(Save);
142 
143  gtk_table_attach_defaults(GTK_TABLE(table),Save,0,1,c->nShown,c->nShown+1);
144 
145  alignment=gtk_alignment_new(0.5,0.5,0,0);
146  gtk_widget_show(alignment);
147  gtk_container_add(GTK_CONTAINER(Save),alignment);
148 
149  hbox=gtk_hbox_new(FALSE,2);
150  gtk_widget_show(hbox);
151  gtk_container_add(GTK_CONTAINER(alignment),hbox);
152 
153  image=gtk_image_new_from_stock("gtk-save",GTK_ICON_SIZE_BUTTON);
154  gtk_widget_show(image);
155  gtk_box_pack_start(GTK_BOX(hbox),image,FALSE,FALSE,0);
156 
157  label=gtk_label_new_with_mnemonic(_("Save"));
158  gtk_widget_show(label);
159  gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
160 
161  g_signal_connect((gpointer)Save,"clicked",
162  G_CALLBACK (on_cuikmove_save),
163  status);
164 
165  GLADE_HOOKUP_OBJECT(window,Save,"Save");
166  GLADE_HOOKUP_OBJECT(window,alignment,"alignment_save");
167  GLADE_HOOKUP_OBJECT(window,hbox,"hbox_save");
168  GLADE_HOOKUP_OBJECT(window,image,"image_save");
169  GLADE_HOOKUP_OBJECT(window,label,"label_save");
170 
171  /***********************************************************/
172  Quit=gtk_button_new();
173  gtk_widget_show(Quit);
174 
175  gtk_table_attach_defaults(GTK_TABLE(table),Quit,1,2,c->nShown,c->nShown+1);
176 
177  gtk_widget_set_size_request(Quit,70,31);
178 
179  alignment=gtk_alignment_new(0.5,0.5,0,0);
180  gtk_widget_show(alignment);
181  gtk_container_add(GTK_CONTAINER(Quit),alignment);
182 
183  hbox=gtk_hbox_new(FALSE,2);
184  gtk_widget_show(hbox);
185  gtk_container_add(GTK_CONTAINER(alignment),hbox);
186 
187  image=gtk_image_new_from_stock("gtk-quit",GTK_ICON_SIZE_BUTTON);
188  gtk_widget_show(image);
189  gtk_box_pack_start(GTK_BOX(hbox),image,FALSE,FALSE,0);
190 
191  label=gtk_label_new_with_mnemonic(_("Quit"));
192  gtk_widget_show(label);
193  gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
194 
195  g_signal_connect((gpointer)Quit,"clicked",
196  G_CALLBACK(on_cuikmove_quit),
197  status);
198 
199  GLADE_HOOKUP_OBJECT(window,Quit,"Quit");
200  GLADE_HOOKUP_OBJECT(window,alignment,"alignment_quit");
201  GLADE_HOOKUP_OBJECT(window,hbox,"hbox_quit");
202  GLADE_HOOKUP_OBJECT(window,image,"image_quit");
203  GLADE_HOOKUP_OBJECT(window,label,"label_quit");
204 
205  /***********************************************************/
206 
207  return window;
208 }
209 
#define FALSE
FALSE.
Definition: boolean.h:30
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
void on_cuikmove_quit(GtkButton *button, gpointer user_data)
Callback function for the quit button.
Definition of the cuikmove control structure.
void GetWorldDOFLabel(unsigned int ndof, char **string, Tworld *w)
Returns a label identifying each degree of freedom.
Definition: world.c:2036
#define TRUE
TRUE.
Definition: boolean.h:21
double * min
Definition: cuikmove.h:28
unsigned int accuracy
Definition: cuikmove.h:26
void on_cuikmove_slider_changed(GtkRange *range, gpointer user_data)
Callback function for the slider bar.
Definition of the cuikmove control structure.
Definition: cuikmove.h:23
Headers of the GTK interface functions for cuikmove.
void on_cuikmove_save(GtkButton *button, gpointer user_data)
Callback function for the save button.
Tworld * w
Definition: cuikmove.h:35
unsigned int nShown
Definition: cuikmove.h:33
double * dof
Definition: cuikmove.h:30
boolean * shown
Definition: cuikmove.h:31
Headers of the GTK callback functions for cuikmove.
unsigned int ndof
Definition: cuikmove.h:27
double * max
Definition: cuikmove.h:29
Headers of the GTK support functions for cuikplay.