Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 3, 2004, 12:29:03 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/buerli: merged back from trunk, with new configure makefile and so forth.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/buerli/gui/orxonox_gui_exec.cc

    r2595 r2707  
    3838  execFrame = new Frame ("Execute-Tags:");
    3939  execBox = new Box ('v');
     40  execFrame->setGroupName ("misc");
    4041 
    4142  start = new Button ("Start");
     
    109110  CONFIG_FILE = fopen (configFile, "w");
    110111  if (CONFIG_FILE)
    111     writeFileText (widget);
     112    writeFileText (widget, 0);
    112113  fclose (CONFIG_FILE);
    113114}
     
    116117   \brief Actually writes into the configuration file to the disk.
    117118   \param widget from which Widget on should be saved.
    118 */
    119 void OrxonoxGuiExec::writeFileText (Widget* widget)
    120 {
     119   \param depth initially "0", and grows higher, while new Groups are bundeled.
     120*/
     121void OrxonoxGuiExec::writeFileText (Widget* widget, int depth)
     122{
     123  int counter = 0;
     124  while (counter < depth && ((widget->is_option>0
     125                              && (strcmp (static_cast<Option*>(widget)->flag_name, "")
     126                                  || strcmp (static_cast<Option*>(widget)->flag_name_short, "")) )
     127                             || (widget->is_option<0
     128                                 && strcmp (static_cast<Packer*>(widget)->getGroupName(), ""))))
     129    {
     130      fprintf (CONFIG_FILE, "  ", depth);
     131      counter++;
     132    }
     133 
     134  // check if it is a Packer, and if it is, check if it has a name and if there is something in it.
     135  if (widget->is_option <0)
     136    {
     137      if (strcmp (static_cast<Packer*>(widget)->getGroupName(), ""))
     138        {
     139          fprintf (CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
     140          writeFileText (static_cast<Packer*>(widget)->down, depth+1);
     141          fprintf(CONFIG_FILE, "\n");
     142        }
     143      else
     144        {
     145          writeFileText (static_cast<Packer*>(widget)->down, depth);
     146        }
     147    }
     148 
    121149  if (widget->is_option >= 1)
    122150    if  (strcmp (static_cast<Option*>(widget)->flag_name, "") || strcmp (static_cast<Option*>(widget)->flag_name_short, ""))
     
    124152        char Buffer[256];
    125153        char* space2under;
    126         sprintf (Buffer, "%s", static_cast<Option*>(widget)->option_name);
     154        sprintf (Buffer, "%s", static_cast<Option*>(widget)->label);
    127155        if (strchr (Buffer, '_'))
    128           cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl; 
     156          cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl;
    129157        while (space2under = strchr(Buffer, ' '))
    130158          {
     
    133161        fprintf (CONFIG_FILE, "%s = %i\n", Buffer, static_cast<Option*>(widget)->value);
    134162      }
    135   switch (widget->is_option)
    136     {
    137     case -1:
    138       writeFileText (static_cast<Container*>(widget)->down);
    139       break;
    140     case -2:
    141       writeFileText (static_cast<Box*>(widget)->down);
    142       break;
    143     }
    144  
     163
    145164  if (widget->next != NULL)
    146     writeFileText (widget->next);
     165    writeFileText (widget->next, depth);
    147166}
    148167
     
    156175  if (CONFIG_FILE)
    157176    {
     177      Widget* groupWidget = widget;
    158178      char Buffer[256] = "";
    159179      char Variable[256]= "";
     
    161181      while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)
    162182        {
     183          if (!strncmp (Buffer, "[", 1))
     184            {
     185              if ((groupWidget = locateGroup (widget, Buffer, 1))==NULL)
     186                {
     187                  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";
     188                  groupWidget = widget;
     189                }
     190            }
    163191          if (!strcmp (Buffer, "="))
    164192            {
     
    171199              fscanf (CONFIG_FILE, "%s", Buffer);
    172200              Value = atoi(Buffer);
    173               readFileText (widget, Variable, Value);
     201              readFileText (groupWidget, Variable, Value, 0);
    174202              sprintf (Variable, "");
    175203            }
     
    179207    }
    180208}
    181 
    182209/**
    183210   \brief Maps Confugurations to the Options.
     
    185212   \param variableName the name of the Variable that should be set up.
    186213   \param variableValue the Value of the Variable that should be set up
    187 */
    188 void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue)
     214   \param depth the depth of the local Widget
     215*/
     216void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue, int depth)
    189217{
    190218  if (widget->is_option >= 1)
    191     if (!strcmp (static_cast<Option*>(widget)->option_name, variableName))
     219    if (!strcmp (static_cast<Option*>(widget)->label, variableName))
    192220        static_cast<Option*>(widget)->value = variableValue;
    193221
    194   switch (widget->is_option)
    195     {
    196     case -1:
    197       readFileText (static_cast<Container*>(widget)->down, variableName, variableValue);
    198       break;
    199     case -2:
    200       readFileText (static_cast<Box*>(widget)->down, variableName, variableValue);
    201       break;
     222  if (widget->is_option < 0)
     223    {
     224      readFileText (static_cast<Packer*>(widget)->down, variableName, variableValue, depth+1);
    202225    }
    203226
    204   if (widget->next != NULL)
    205     readFileText (widget->next, variableName, variableValue);
     227  if (widget->next != NULL && depth !=0)
     228    readFileText (widget->next, variableName, variableValue, depth);
     229}
     230
     231/**
     232   \brief locates a Group member
     233*/
     234Widget* OrxonoxGuiExec::locateGroup(Widget* widget, char* groupName, int depth)
     235{
     236  Widget* tmp;
     237
     238  // removes the trailing and ending [ ].
     239  if (!strncmp (groupName, "[", 1))
     240    {
     241      groupName = groupName+1;
     242      groupName[strlen(groupName)-1] = '\0';
     243    }
     244
     245  if (widget->is_option < 0)
     246    {
     247      if (!strcmp(groupName, static_cast<Packer*>(widget)->getGroupName()))
     248        {
     249          return widget;
     250        }
     251      else
     252        {
     253          if ((tmp = locateGroup (static_cast<Packer*>(widget)->down, groupName, depth+1)) != NULL)
     254            return tmp;
     255        }
     256    }
     257 
     258  if (widget->next != NULL && depth != 0)
     259    {
     260      if ((tmp = locateGroup (widget->next, groupName, depth)) != NULL)
     261        return tmp;
     262    }
     263  return NULL;
    206264}
    207265
Note: See TracChangeset for help on using the changeset viewer.