00001 #include "cuikplay.h"
00002
00003 #include "world.h"
00004 #include "box_list.h"
00005 #include "error.h"
00006
00007 #include "cuikplay_interface.h"
00008 #include "cuikplay_support.h"
00009 #include "cuikplay.h"
00010
00011 #include <gtk/gtk.h>
00012
00013 #include <unistd.h>
00014 #include <time.h>
00015
00057 int main(int argc, char **arg)
00058 {
00059
00060 if (argc>2)
00061 {
00062 Tworld world;
00063 Tparameters parameters;
00064 Tfilename fsols;
00065 Tfilename fparam;
00066 Tfilename fworld;
00067
00068 Tlist sol_box_list;
00069 Titerator it;
00070
00071 Tplot3d pt;
00072
00073 TCuikPlayControl status;
00074 double frameDelay,axesLength,t;
00075
00076 GtkWidget *window1,*slider;
00077
00078 CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
00079 InitParametersFromFile(GetFileFullName(&fparam),¶meters);
00080
00081 CreateFileName(NULL,arg[1],NULL,WORLD_EXT,&fworld);
00082 InitWorldFromFile(¶meters,&fworld,&world);
00083
00084 CreateFileName(NULL,arg[2],NULL,SOL_EXT,&fsols);
00085 if (!ReadListOfBoxes(GetFileFullName(&fsols),&sol_box_list))
00086 Error("Solution file can not be opened");
00087
00088 InitIterator(&it,&sol_box_list);
00089 First(&it);
00090
00091 if (argc>3)
00092 axesLength=atof(arg[3]);
00093 else
00094 axesLength=0;
00095
00096 if (argc>4)
00097 frameDelay=atof(arg[4]);
00098 else
00099 frameDelay=0.1;
00100
00101 InitPlot3d(NULL,FALSE,argc,arg,&pt);
00102
00103 PlotWorld(&pt,axesLength,&world);
00104
00105 MoveWorld(&pt,(Tbox *)GetCurrent(&it),&world);
00106
00107 status.maxFrame=ListSize(&sol_box_list);
00108 if (status.maxFrame==0)
00109 Error("Empty list of solutions");
00110
00111 status.end=FALSE;
00112 status.mode=0;
00113 status.time=(double)time(NULL)+frameDelay;
00114 status.currentFrame=0;
00115 status.nextFrame=0;
00116
00117 gtk_set_locale();
00118 gtk_init(&argc,&arg);
00119
00120 window1=create_window1((gpointer)(&status),status.maxFrame);
00121 slider=lookup_widget(window1,"hscale1");
00122 gtk_widget_show(window1);
00123
00124 #if (_DEBUG>1)
00125 fprintf(stderr,"Max frame %u \n",status.maxFrame);
00126 #endif
00127 while(!status.end)
00128 {
00129 if (status.mode==0)
00130 {
00131 if (status.currentFrame<(status.maxFrame-1))
00132 {
00133 t=(double)time(NULL);
00134 if (t>status.time)
00135 {
00136
00137
00138
00139 double v;
00140
00141 v=(double)(status.currentFrame+1);
00142
00143 #if (_DEBUG>1)
00144 fprintf(stderr,"Moving Slider from %g to %g \n",
00145 gtk_range_get_value(GTK_RANGE(slider)),v);
00146 #endif
00147
00148 gtk_range_set_value(GTK_RANGE(slider),v);
00149 status.time=t+frameDelay;
00150 }
00151 }
00152 else
00153 status.mode=1;
00154 }
00155
00156 if (status.currentFrame!=status.nextFrame)
00157 {
00158 if (status.nextFrame<status.maxFrame)
00159 {
00160 #if (_DEBUG>1)
00161 fprintf(stderr,"Displaying: %u\n",status.nextFrame);
00162 #endif
00163 MoveTo(status.nextFrame,&it);
00164 MoveWorld(&pt,(Tbox *)GetCurrent(&it),&world);
00165 status.currentFrame=status.nextFrame;
00166 }
00167 else
00168 {
00169 status.currentFrame=status.nextFrame=status.maxFrame;
00170 status.mode=1;
00171 }
00172 }
00173 gtk_main_iteration_do(FALSE);
00174 }
00175
00176 ClosePlot3d(TRUE,0,0,0,&pt);
00177
00178 DeleteListOfBoxes(&sol_box_list);
00179
00180 DeleteFileName(&fsols);
00181 DeleteFileName(&fworld);
00182 DeleteFileName(&fparam);
00183 }
00184 else
00185 {
00186 fprintf(stdout," Wrong number of parameters.\n");
00187 fprintf(stdout," Use:\n");
00188 fprintf(stdout," cuikplay <world>.world <solutions>.sol [<axes> <delay>]\n");
00189 fprintf(stdout," Where:\n");
00190 fprintf(stdout," <world>: File describing the problem\n");
00191 fprintf(stdout," <solutions>: Is the path of solutions to be animated\n");
00192 fprintf(stdout," <axes>: Optional. Length for the axes for each link.\n");
00193 fprintf(stdout," The default value is 0, i.e., not to display them.\n");
00194 fprintf(stdout," <delay>: Optional. Delay (in seconds) between frames.\n");
00195 fprintf(stdout," The default delay is 0.1 seconds.\n");
00196 fprintf(stdout," File extensions are not required\n");
00197 }
00198
00199 return(EXIT_SUCCESS);
00200 }