Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3423 in orxonox.OLD for orxonox/trunk/src/gui/orxonox_gui_exec.cc


Ignore:
Timestamp:
Feb 27, 2005, 7:11:19 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged branches/updater back into the trunk
merged with command: svn merge branches/updater trunk -r 3241:HEAD
resolved conflicts in debug.h in favor of the trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/gui/orxonox_gui_exec.cc

    r3187 r3423  
    2828#include <string>
    2929
     30HashTable* orxonoxFlagHash;
     31
    3032/**
    3133    \brief Creates the Exec-Frame
    32     \param orxonoxGUI ExecFrame needs to know where to get the Options from
    33 */
    34 OrxonoxGuiExec::OrxonoxGuiExec (Window* orxonoxGUI)
    35 {
    36   configFile = (char*)malloc (512*sizeof (char));
    37 
    38   execFrame = new Frame ("Execute-Tags:");
    39   execBox = new Box ('v');
    40   execFrame->setGroupName ("misc");
     34*/
     35OrxonoxGuiExec::OrxonoxGuiExec(void)
     36{
     37  configFile =(char*)malloc(512*sizeof(char));
     38
     39  this->execFrame = new Frame("Execute-Tags:");
     40  this->execBox = new Box('v');
     41  this->execFrame->setGroupName("misc");
    4142 
    42   start = new Button ("Start");
     43  this->start = new Button("Start");
    4344#ifdef HAVE_GTK2
    44   start->connectSignal ("clicked", startOrxonox);
     45  this->start->connectSignal("clicked", this, startOrxonox);
    4546#endif /* HAVE_GTK2 */
    46   execBox->fill (start);
    47   saveSettings = new CheckButton ("Save Settings");
    48   saveSettings->value = 1;
    49   saveSettings->saveable = true;
    50   execBox->fill (saveSettings);
    51   verboseMode = new Menu ("verbose mode", "no output", "verbose", "debug", "lastItem");
    52   verboseMode->setFlagName ("verbose", "v", 0);
    53   verboseMode->saveable = true;
    54   execBox->fill (verboseMode);
    55   alwaysShow = new CheckButton ("Always Show this Menu");
    56   alwaysShow->setFlagName ("gui", "g", 0);
    57   alwaysShow->saveable = true;
    58   execBox->fill (alwaysShow);
    59   quit = new Button ("Quit");
     47  this->execBox->fill(start);
     48  this->saveSettings = new CheckButton("Save Settings");
     49  this->saveSettings->value = 1;
     50  this->saveSettings->saveability();
     51  this->execBox->fill(this->saveSettings);
     52  this->verboseMode = new Menu("verbose mode", "no output", "error", "warning", "info", "lastItem");
     53  this->verboseMode->setFlagName("verbose", "v", 0);
     54  this->verboseMode->saveability();
     55  this->execBox->fill(this->verboseMode);
     56  this->alwaysShow = new CheckButton("Always Show this Menu");
     57  this->alwaysShow->setFlagName("gui", "g", 0);
     58  this->alwaysShow->saveability();
     59  this->execBox->fill(this->alwaysShow);
     60  this->quit = new Button("Quit");
    6061#ifdef HAVE_GTK2
    61   quit->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit);
     62  this->quit->connectSignal("clicked", this, OrxonoxGuiExec::quitOrxonox);
     63  //  Window::mainWindow->connectSignal("remove", this, OrxonoxGuiExec::quitOrxonox);
     64  Window::mainWindow->connectSignal("destroy", this, OrxonoxGuiExec::quitOrxonox);
    6265#endif /* HAVE_GTK2 */
    63   execBox->fill (quit);
    64 
    65   execFrame->fill (execBox);
     66  this->execBox->fill(this->quit);
     67
     68  this->execFrame->fill(this->execBox);
     69}
     70
     71/**
     72   \brief Destructs the Execution-stuff
     73*/
     74OrxonoxGuiExec::~OrxonoxGuiExec(void)
     75{
     76  if(this->configFile)
     77    delete []this->configFile;
    6678}
    6779
     
    7082   \return Returns the Exec-frame
    7183*/
    72 Widget* OrxonoxGuiExec::getWidget ()
     84Widget* OrxonoxGuiExec::getWidget(void)
    7385{
    7486  return execFrame;
     
    7890
    7991/**
    80    \brief Sets the location of the configuration File.\n
    81    * The name will be parsed from ~/ to /home/[username] on unix and c:/Documents and Settings/username/Settings/ on Windows
     92   \brief Sets the location of the configuration File.
    8293   \param filename the location of the configFile
    83 */
    84 void OrxonoxGuiExec::setFilename (char* filename)
    85 {
    86   char* buffer = (char*) malloc (512*sizeof(buffer));
    87   sprintf (buffer, "%s", filename);
    88   if (!strncmp (buffer, "~/", 2))
     94
     95   \todo: memory allocation could be better.
     96
     97   The name will be parsed from ~/ to /home/[username] on unix and c:/Documents and Settings/username/Settings/ on Windows
     98*/
     99void OrxonoxGuiExec::setFilename(char* filename)
     100{
     101  char* buffer = (char*)malloc(2048*sizeof(char));
     102  sprintf(buffer, "%s", filename);
     103  if(!strncmp(buffer, "~/", 2))
    89104  {
    90105#ifdef __WIN32__
    91     sprintf (configFile, "%s/%s", getenv ("USERPROFILE"), buffer+2);
     106    sprintf(configFile, "%s/%s", getenv("USERPROFILE"), buffer+2);
    92107#else
    93     sprintf (configFile, "%s/%s", getenv ("HOME"), buffer+2);
     108    sprintf(configFile, "%s/%s", getenv("HOME"), buffer+2);
    94109#endif
    95110  }
    96   else if (buffer)
    97     sprintf(configFile, "%s", buffer);
    98   delete buffer;
     111  else if(buffer)
     112    strcpy(this->configFile, buffer);
     113  free (buffer);
     114}
     115
     116/**
     117   \returns The name of the Configuration-File
     118*/
     119char* OrxonoxGuiExec::getConfigFile(void)
     120{
     121  return this->configFile;
    99122}
    100123
     
    103126   \return 1 if it should 0 if not/
    104127*/
    105 int OrxonoxGuiExec::shouldsave ()
    106 {
    107   return (static_cast<Option*>(saveSettings)->value);
     128int OrxonoxGuiExec::shouldsave()
     129{
     130  return(static_cast<Option*>(this->saveSettings)->value);
    108131}
    109132
     
    112135    \param widget from which Widget on should be saved.
    113136
    114     this Function only opens and closes the file, in between OrxonoxGuiExec::writeFileText (Widget* widget) will execute the real writing process.
    115 */
    116 void OrxonoxGuiExec::writeToFile (Widget* widget)
    117 {
    118   CONFIG_FILE = fopen (configFile, "w");
    119   if (CONFIG_FILE)
    120     writeFileText (widget, 0);
    121   fclose (CONFIG_FILE);
     137    this Function only opens and closes the file, in between OrxonoxGuiExec::writeFileText(Widget* widget) will execute the real writing process.
     138*/
     139void OrxonoxGuiExec::writeToFile(Widget* widget)
     140{
     141  this->CONFIG_FILE = fopen(configFile, "w");
     142  if(this->CONFIG_FILE)
     143    this->writeFileText(widget, 0);
     144  fclose(this->CONFIG_FILE);
    122145}
    123146
     
    127150   \param depth initially "0", and grows higher, while new Groups are bundeled.
    128151*/
    129 void OrxonoxGuiExec::writeFileText (Widget* widget, int depth)
     152void OrxonoxGuiExec::writeFileText(Widget* widget, int depth)
    130153{
    131154  int counter = 0;
    132   while (counter < depth && ((widget->isOption>0
    133                               && (static_cast<Option*>(widget)->saveable) )
    134                              || (widget->isOption<0
    135                                  && static_cast<Packer*>(widget)->getGroupName())))
    136     {
    137       fprintf (CONFIG_FILE, "  ", depth);
     155  while(counter < depth &&((widget->isOption>0
     156                              &&(static_cast<Option*>(widget)->isSaveable()))
     157                             ||(widget->isOption<0
     158                                && static_cast<Packer*>(widget)->getGroupName())))
     159    {
     160      fprintf(this->CONFIG_FILE, "  ", depth);
    138161      counter++;
    139162    }
    140163 
    141164  // check if it is a Packer, and if it is, check if it has a name and if there is something in it.
    142   if (widget->isOption <0)
    143     {
    144       if (static_cast<Packer*>(widget)->getGroupName())
    145         {
    146           fprintf (CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
    147           writeFileText (static_cast<Packer*>(widget)->down, depth+1);
     165  if(widget->isOption <0)
     166    {
     167      if(static_cast<Packer*>(widget)->getGroupName())
     168        {
     169          fprintf(CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
     170          this->writeFileText(static_cast<Packer*>(widget)->down, depth+1);
    148171          fprintf(CONFIG_FILE, "\n");
    149172        }
    150173      else
    151174        {
    152           writeFileText (static_cast<Packer*>(widget)->down, depth);
     175          this->writeFileText(static_cast<Packer*>(widget)->down, depth);
    153176        }
    154177    }
    155   //  if (widget->isOption == 0)
    156   //    printf ("%s\n",widget->label);
    157   if (widget->isOption >= 1)
    158     if  (static_cast<Option*>(widget)->saveable)
     178  //  if(widget->isOption == 0)
     179  //    printf("%s\n",widget->title);
     180  if(widget->isOption >= 1)
     181    if (static_cast<Option*>(widget)->isSaveable())
    159182      {
    160183        char Buffer[256];
    161184        char* space2under;
    162         strcpy (Buffer, static_cast<Option*>(widget)->label);
    163         if (strchr (Buffer, '_'))
     185        strcpy(Buffer, static_cast<Option*>(widget)->title);
     186        if(strchr(Buffer, '_'))
    164187          cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl;
    165         while (space2under = strchr(Buffer, ' '))
     188        while(space2under = strchr(Buffer, ' '))
    166189          {
    167190            space2under[0] = '_';
    168191          }
    169         if (widget->isOption <=3)
    170           fprintf (CONFIG_FILE, "%s = %d\n", Buffer, static_cast<Option*>(widget)->value);
    171         else if (widget->isOption == 5)
    172           fprintf (CONFIG_FILE, "%s = %s\n", Buffer, static_cast<OptionLabel*>(widget)->cValue);
     192        if(widget->isOption <=3)
     193          fprintf(CONFIG_FILE, "%s = %d\n", Buffer, static_cast<Option*>(widget)->value);
     194        else if(widget->isOption == 5)
     195          fprintf(CONFIG_FILE, "%s = %s\n", Buffer, static_cast<OptionLabel*>(widget)->cValue);
    173196      }
    174197
    175   if (widget->next != NULL)
    176     writeFileText (widget->next, depth);
     198  if(widget->next != NULL)
     199    this->writeFileText(widget->next, depth);
    177200}
    178201
     
    181204   \param widget from which Widget on should be saved.
    182205*/
    183 void OrxonoxGuiExec::readFromFile (Widget* widget)
    184 {
    185   CONFIG_FILE = fopen (configFile, "r");
    186   if (CONFIG_FILE)
     206void OrxonoxGuiExec::readFromFile(Widget* widget)
     207{
     208  this->CONFIG_FILE = fopen(configFile, "r");
     209  VarInfo varInfo;
     210  if(this->CONFIG_FILE)
    187211    {
    188212      Widget* groupWidget = widget;
     
    190214      char Variable[256]= "";
    191215      char* Value;
    192       while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)
     216      while(fscanf(this->CONFIG_FILE, "%s", Buffer) != EOF)
    193217        {
    194218          // group-search //
    195           if (!strncmp (Buffer, "[", 1))
     219          if(!strncmp(Buffer, "[", 1))
    196220            {
    197               if ((groupWidget = locateGroup (widget, Buffer, 1))==NULL)
     221              if((groupWidget = locateGroup(widget, Buffer, 1))==NULL)
    198222                {
    199223                  cout << "!!There is no group called " << Buffer << " in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n";
    200224                  groupWidget = widget;
    201225                }
     226              else
     227                PRINT(3)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName);
    202228            }
    203229          // option-setting //
    204           if (!strcmp (Buffer, "="))
     230          if(!strcmp(Buffer, "="))
    205231            {
    206232              char* under2space;
    207               while (under2space = strchr(Variable, '_'))
     233              while(under2space = strchr(Variable, '_'))
    208234                {
    209                   sprintf (under2space, " %s", under2space+1);
     235                  sprintf(under2space, " %s", under2space+1);
    210236                }
    211237             
    212               fscanf (CONFIG_FILE, "%s", Buffer);
    213               Value = Buffer;
    214               readFileText (groupWidget, Variable, Value, 0);
    215               sprintf (Variable, "");
     238              fscanf(this->CONFIG_FILE, "%s", Buffer);
     239              varInfo.variableName = Variable;
     240              varInfo.variableValue = Buffer;
     241              groupWidget->walkThrough(this->readFileText, &varInfo, 0);
     242              sprintf(Variable, "");
    216243            }
    217           sprintf (Variable, "%s", Buffer);
    218         }
    219       widget->walkThrough(widget->setOptions);
    220     }
    221 }
     244          sprintf(Variable, "%s", Buffer);
     245        }
     246      widget->walkThrough(widget->setOptions, 0);
     247    }
     248}
     249
    222250/**
    223251   \brief Maps Confugurations to the Options.
    224252   \param widget which widget downwards
    225    \param variableName the name of the Variable that should be set up.
    226    \param variableValue the Value of the Variable that should be set up
    227    \param depth the depth of the local Widget
    228 */
    229 void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, char* variableValue, int depth)
    230 {
    231   if (widget->isOption >= 1 && widget->isOption <= 3)
    232     {
    233       if (!strcmp (static_cast<Option*>(widget)->label, variableName))
    234         static_cast<Option*>(widget)->value = atoi(variableValue);
    235     }
    236   else if (widget->isOption == 5)
    237     {
    238        if (!strcmp (static_cast<Option*>(widget)->label, variableName))
    239         static_cast<OptionLabel*>(widget)->setValue(variableValue);
    240     }
    241   if (widget->isOption < 0)
    242     {
    243       readFileText (static_cast<Packer*>(widget)->down, variableName, variableValue, depth+1);
    244     }
    245 
    246   if (widget->next != NULL && depth !=0)
    247     readFileText (widget->next, variableName, variableValue, depth);
     253   \param varInfo Information about the Variable to read
     254*/
     255void OrxonoxGuiExec::readFileText(Widget* widget, void* varInfo)
     256{
     257  VarInfo* info =(VarInfo*)varInfo;
     258  if(widget->title && !strcmp(widget->title, info->variableName))
     259    {
     260      PRINT(3)("Located Option %s.\n", widget->title);
     261      if(widget->isOption >= 1 && widget->isOption <= 3)
     262        {
     263          static_cast<Option*>(widget)->value = atoi(info->variableValue);
     264          static_cast<Option*>(widget)->redraw(); //!< \todo change this to setValue.
     265        }
     266      else if(widget->isOption == 5)
     267        static_cast<OptionLabel*>(widget)->setValue(info->variableValue);
     268    }
    248269}
    249270
     
    254275   \param depth The Depth of the search seen from the first widget we searched from.
    255276   \returns The Widget that holds the Group, or the NULL if the Group wasn't found.
     277
     278   \todo do this in gui-gtk.
    256279*/
    257280Widget* OrxonoxGuiExec::locateGroup(Widget* widget, char* groupName, int depth)
     
    260283
    261284  // removes the trailing and ending [ ].
    262   if (!strncmp (groupName, "[", 1))
     285  if(!strncmp(groupName, "[", 1))
    263286    {
    264287      groupName = groupName+1;
     
    266289    }
    267290
    268   if (widget->isOption < 0)
    269     {
    270       if (static_cast<Packer*>(widget)->getGroupName() && !strcmp(groupName, static_cast<Packer*>(widget)->getGroupName()))
     291  if(widget->isOption < 0)
     292    {
     293      if(static_cast<Packer*>(widget)->getGroupName() && !strcmp(groupName, static_cast<Packer*>(widget)->getGroupName()))
    271294        {
    272295          return widget;
     
    274297      else
    275298        {
    276           if ((tmp = locateGroup (static_cast<Packer*>(widget)->down, groupName, depth+1)) != NULL)
     299          if((tmp = locateGroup(static_cast<Packer*>(widget)->down, groupName, depth+1)) != NULL)
    277300            return tmp;
    278301        }
    279302    }
    280303 
    281   if (widget->next != NULL && depth != 0)
    282     {
    283       if ((tmp = locateGroup (widget->next, groupName, depth)) != NULL)
     304  if(widget->next != NULL && depth != 0)
     305    {
     306      if((tmp = locateGroup(widget->next, groupName, depth)) != NULL)
    284307        return tmp;
    285308    }
     
    289312#ifdef HAVE_GTK2
    290313/**
    291    \brief Starts ORXONOX. (not really implemented yet, but the function is there.\n
    292    This is a Signal and can be executed through Widget::signal_connect
     314   \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n
    293315   \param widget the widget that executed the start command
    294316   \param data additional data
    295 */
    296 gint startOrxonox (GtkWidget *widget, Widget* data)
    297 {
     317
     318   This is a Signal and can be executed through Widget::signal_connect
     319*/
     320int OrxonoxGuiExec::startOrxonox(GtkWidget* widget, void* data)
     321{
     322  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
     323  if(exec->shouldsave())
     324    exec->writeToFile(Window::mainWindow);
    298325  cout << "Starting Orxonox" <<endl;
    299 }
     326  gtk_main_quit();
     327  system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real(coded not over the shell)
     328}
     329
     330/**
     331   \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n
     332   \param widget the widget that executed the start command
     333   \param data additional data
     334
     335   This is a Signal and can be executed through Widget::signal_connect
     336*/
     337int OrxonoxGuiExec::quitOrxonox(GtkWidget* widget, void* data)
     338{
     339  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
     340  PRINT(3)( "Quitting Orxonox %p\n", exec);
     341  if(exec->shouldsave())
     342    exec->writeToFile(Window::mainWindow);
     343  gtk_main_quit();
     344}
     345#else /* HAVE_GTK2 */
     346/**
     347   \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n
     348   \param widget the widget that executed the start command
     349   \param data additional data
     350*/
     351int OrxonoxGuiExec::startOrxonox(void* widget, void* data)
     352{
     353  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
     354  PRINT(3)("Starting Orxonox\n");
     355  if(exec->shouldsave())
     356    exec->writeToFile(Window::mainWindow);
     357  system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real(coded not over the shell)
     358}
     359/**
     360   \brief Quits ORXONOX.
     361   \param widget the widget that executed the Quit command
     362   \param data additional data
     363
     364   This is a Signal and can be executed through Widget::signal_connect
     365*/
     366int OrxonoxGuiExec::quitOrxonox(void* widget, void* data)
     367{
     368  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
     369  PRINT(3)("Quiting Orxonox");
     370  if(exec->shouldsave())
     371    exec->writeToFile(Window::mainWindow);
     372}
     373
    300374#endif /* HAVE_GTK2 */
Note: See TracChangeset for help on using the changeset viewer.