Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 3, 2005, 12:13:38 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/updater: code-standartisation updated in all files.

  1. member → this→member
  2. function (bla) → function(bla)
  3. other small fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/updater/src/gui/orxonox_gui_exec.cc

    r3301 r3315  
    3434    \param orxonoxGUI ExecFrame needs to know where to get the Options from
    3535*/
    36 OrxonoxGuiExec::OrxonoxGuiExec (Window* orxonoxGUI)
    37 {
    38   configFile = (char*)malloc (512*sizeof (char));
    39 
    40   execFrame = new Frame ("Execute-Tags:");
    41   execBox = new Box ('v');
    42   execFrame->setGroupName ("misc");
     36OrxonoxGuiExec::OrxonoxGuiExec(void)
     37{
     38  configFile =(char*)malloc(512*sizeof(char));
     39
     40  this->execFrame = new Frame("Execute-Tags:");
     41  this->execBox = new Box('v');
     42  this->execFrame->setGroupName("misc");
    4343 
    44   start = new Button ("Start");
     44  this->start = new Button("Start");
    4545#ifdef HAVE_GTK2
    46   start->connectSignal ("clicked", this, startOrxonox);
     46  this->start->connectSignal("clicked", this, startOrxonox);
    4747#endif /* HAVE_GTK2 */
    48   execBox->fill (start);
    49   saveSettings = new CheckButton ("Save Settings");
    50   saveSettings->value = 1;
    51   saveSettings->saveability();
    52   execBox->fill (saveSettings);
    53   verboseMode = new Menu ("verbose mode", "no output", "error", "warning", "info", "lastItem");
    54   verboseMode->setFlagName ("verbose", "v", 0);
    55   verboseMode->saveability();
    56   execBox->fill (verboseMode);
    57   alwaysShow = new CheckButton ("Always Show this Menu");
    58   alwaysShow->setFlagName ("gui", "g", 0);
    59   alwaysShow->saveability();
    60   execBox->fill (alwaysShow);
    61   quit = new Button ("Quit");
     48  this->execBox->fill(start);
     49  this->saveSettings = new CheckButton("Save Settings");
     50  this->saveSettings->value = 1;
     51  this->saveSettings->saveability();
     52  this->execBox->fill(this->saveSettings);
     53  this->verboseMode = new Menu("verbose mode", "no output", "error", "warning", "info", "lastItem");
     54  this->verboseMode->setFlagName("verbose", "v", 0);
     55  this->verboseMode->saveability();
     56  this->execBox->fill(this->verboseMode);
     57  this->alwaysShow = new CheckButton("Always Show this Menu");
     58  this->alwaysShow->setFlagName("gui", "g", 0);
     59  this->alwaysShow->saveability();
     60  this->execBox->fill(this->alwaysShow);
     61  this->quit = new Button("Quit");
    6262#ifdef HAVE_GTK2
    63   quit->connectSignal ("clicked", this, OrxonoxGuiExec::quitOrxonox);
    64   orxonoxGUI->connectSignal ("destroy", this, OrxonoxGuiExec::quitOrxonox);
    65   //! orxonoxGUI->connectSignal ("delete_event", this, OrxonoxGuiExec::quitOrxonox); \todo fix this to work.
     63  this->quit->connectSignal("clicked", this, OrxonoxGuiExec::quitOrxonox);
     64  Window::mainWindow->connectSignal("destroy", this, OrxonoxGuiExec::quitOrxonox);
     65  //! orxonoxGUI->connectSignal("delete_event", this, OrxonoxGuiExec::quitOrxonox); \todo fix this to work.
    6666#endif /* HAVE_GTK2 */
    67   execBox->fill (quit);
    68 
    69   execFrame->fill (execBox);
     67  this->execBox->fill(this->quit);
     68
     69  this->execFrame->fill(this->execBox);
    7070}
    7171
     
    7474   \return Returns the Exec-frame
    7575*/
    76 Widget* OrxonoxGuiExec::getWidget ()
     76Widget* OrxonoxGuiExec::getWidget(void)
    7777{
    7878  return execFrame;
     
    8585   \param filename the location of the configFile
    8686
     87   \todo: memory allocation could be better.
     88
    8789   The name will be parsed from ~/ to /home/[username] on unix and c:/Documents and Settings/username/Settings/ on Windows
    8890*/
    89 void OrxonoxGuiExec::setFilename (char* filename)
    90 {
    91   char* buffer = (char*) malloc (512*sizeof(buffer));
    92   sprintf (buffer, "%s", filename);
    93   if (!strncmp (buffer, "~/", 2))
     91void OrxonoxGuiExec::setFilename(char* filename)
     92{
     93  char* buffer = (char*)malloc(2048*sizeof(char));
     94  sprintf(buffer, "%s", filename);
     95  if(!strncmp(buffer, "~/", 2))
    9496  {
    9597#ifdef __WIN32__
    96     sprintf (configFile, "%s/%s", getenv ("USERPROFILE"), buffer+2);
     98    sprintf(configFile, "%s/%s", getenv("USERPROFILE"), buffer+2);
    9799#else
    98     sprintf (configFile, "%s/%s", getenv ("HOME"), buffer+2);
     100    sprintf(configFile, "%s/%s", getenv("HOME"), buffer+2);
    99101#endif
    100102  }
    101   else if (buffer)
    102     sprintf(configFile, "%s", buffer);
    103   delete buffer;
     103  else if(buffer)
     104    strcpy(this->configFile, buffer);
     105  free (buffer);
    104106}
    105107
     
    109111char* OrxonoxGuiExec::getConfigFile(void)
    110112{
    111   return configFile;
     113  return this->configFile;
    112114}
    113115
     
    116118   \return 1 if it should 0 if not/
    117119*/
    118 int OrxonoxGuiExec::shouldsave ()
    119 {
    120   return (static_cast<Option*>(saveSettings)->value);
     120int OrxonoxGuiExec::shouldsave()
     121{
     122  return(static_cast<Option*>(this->saveSettings)->value);
    121123}
    122124
     
    125127    \param widget from which Widget on should be saved.
    126128
    127     this Function only opens and closes the file, in between OrxonoxGuiExec::writeFileText (Widget* widget) will execute the real writing process.
    128 */
    129 void OrxonoxGuiExec::writeToFile (Widget* widget)
    130 {
    131   CONFIG_FILE = fopen (configFile, "w");
    132   if (CONFIG_FILE)
    133     writeFileText (widget, 0);
    134   fclose (CONFIG_FILE);
     129    this Function only opens and closes the file, in between OrxonoxGuiExec::writeFileText(Widget* widget) will execute the real writing process.
     130*/
     131void OrxonoxGuiExec::writeToFile(Widget* widget)
     132{
     133  this->CONFIG_FILE = fopen(configFile, "w");
     134  if(this->CONFIG_FILE)
     135    this->writeFileText(widget, 0);
     136  fclose(this->CONFIG_FILE);
    135137}
    136138
     
    140142   \param depth initially "0", and grows higher, while new Groups are bundeled.
    141143*/
    142 void OrxonoxGuiExec::writeFileText (Widget* widget, int depth)
     144void OrxonoxGuiExec::writeFileText(Widget* widget, int depth)
    143145{
    144146  int counter = 0;
    145   while (counter < depth && ((widget->isOption>0
    146                               && (static_cast<Option*>(widget)->isSaveable()) )
    147                              || (widget->isOption<0
     147  while(counter < depth &&((widget->isOption>0
     148                              &&(static_cast<Option*>(widget)->isSaveable()) )
     149                             ||(widget->isOption<0
    148150                                 && static_cast<Packer*>(widget)->getGroupName())))
    149151    {
    150       fprintf (CONFIG_FILE, "  ", depth);
     152      fprintf(this->CONFIG_FILE, "  ", depth);
    151153      counter++;
    152154    }
    153155 
    154156  // check if it is a Packer, and if it is, check if it has a name and if there is something in it.
    155   if (widget->isOption <0)
    156     {
    157       if (static_cast<Packer*>(widget)->getGroupName())
    158         {
    159           fprintf (CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
    160           writeFileText (static_cast<Packer*>(widget)->down, depth+1);
     157  if(widget->isOption <0)
     158    {
     159      if(static_cast<Packer*>(widget)->getGroupName())
     160        {
     161          fprintf(CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
     162          this->writeFileText(static_cast<Packer*>(widget)->down, depth+1);
    161163          fprintf(CONFIG_FILE, "\n");
    162164        }
    163165      else
    164166        {
    165           writeFileText (static_cast<Packer*>(widget)->down, depth);
     167          this->writeFileText(static_cast<Packer*>(widget)->down, depth);
    166168        }
    167169    }
    168   //  if (widget->isOption == 0)
    169   //    printf ("%s\n",widget->title);
    170   if (widget->isOption >= 1)
    171     if  (static_cast<Option*>(widget)->isSaveable())
     170  //  if(widget->isOption == 0)
     171  //    printf("%s\n",widget->title);
     172  if(widget->isOption >= 1)
     173    if (static_cast<Option*>(widget)->isSaveable())
    172174      {
    173175        char Buffer[256];
    174176        char* space2under;
    175         strcpy (Buffer, static_cast<Option*>(widget)->title);
    176         if (strchr (Buffer, '_'))
     177        strcpy(Buffer, static_cast<Option*>(widget)->title);
     178        if(strchr(Buffer, '_'))
    177179          cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl;
    178         while (space2under = strchr(Buffer, ' '))
     180        while(space2under = strchr(Buffer, ' '))
    179181          {
    180182            space2under[0] = '_';
    181183          }
    182         if (widget->isOption <=3)
    183           fprintf (CONFIG_FILE, "%s = %d\n", Buffer, static_cast<Option*>(widget)->value);
    184         else if (widget->isOption == 5)
    185           fprintf (CONFIG_FILE, "%s = %s\n", Buffer, static_cast<OptionLabel*>(widget)->cValue);
     184        if(widget->isOption <=3)
     185          fprintf(CONFIG_FILE, "%s = %d\n", Buffer, static_cast<Option*>(widget)->value);
     186        else if(widget->isOption == 5)
     187          fprintf(CONFIG_FILE, "%s = %s\n", Buffer, static_cast<OptionLabel*>(widget)->cValue);
    186188      }
    187189
    188   if (widget->next != NULL)
    189     writeFileText (widget->next, depth);
     190  if(widget->next != NULL)
     191    this->writeFileText(widget->next, depth);
    190192}
    191193
     
    194196   \param widget from which Widget on should be saved.
    195197*/
    196 void OrxonoxGuiExec::readFromFile (Widget* widget)
    197 {
    198   CONFIG_FILE = fopen (configFile, "r");
     198void OrxonoxGuiExec::readFromFile(Widget* widget)
     199{
     200  this->CONFIG_FILE = fopen(configFile, "r");
    199201  VarInfo varInfo;
    200   if (CONFIG_FILE)
     202  if(this->CONFIG_FILE)
    201203    {
    202204      Widget* groupWidget = widget;
     
    204206      char Variable[256]= "";
    205207      char* Value;
    206       while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)
     208      while(fscanf(this->CONFIG_FILE, "%s", Buffer) != EOF)
    207209        {
    208210          // group-search //
    209           if (!strncmp (Buffer, "[", 1))
     211          if(!strncmp(Buffer, "[", 1))
    210212            {
    211               if ((groupWidget = locateGroup (widget, Buffer, 1))==NULL)
     213              if((groupWidget = locateGroup(widget, Buffer, 1))==NULL)
    212214                {
    213215                  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";
     
    216218            }
    217219          // option-setting //
    218           if (!strcmp (Buffer, "="))
     220          if(!strcmp(Buffer, "="))
    219221            {
    220222              char* under2space;
    221               while (under2space = strchr(Variable, '_'))
     223              while(under2space = strchr(Variable, '_'))
    222224                {
    223                   sprintf (under2space, " %s", under2space+1);
     225                  sprintf(under2space, " %s", under2space+1);
    224226                }
    225227             
    226               fscanf (CONFIG_FILE, "%s", Buffer);
     228              fscanf(this->CONFIG_FILE, "%s", Buffer);
    227229              varInfo.variableName = Variable;
    228230              varInfo.variableValue = Buffer;
    229               groupWidget->walkThrough(readFileText, &varInfo, 0);
    230               sprintf (Variable, "");
     231              groupWidget->walkThrough(this->readFileText, &varInfo, 0);
     232              sprintf(Variable, "");
    231233            }
    232           sprintf (Variable, "%s", Buffer);
     234          sprintf(Variable, "%s", Buffer);
    233235        }
    234236      widget->walkThrough(widget->setOptions, 0);
     
    240242   \param varInfo Information about the Variable to read
    241243*/
    242 void OrxonoxGuiExec::readFileText (Widget* widget, void* varInfo)
    243 {
    244   VarInfo* info = (VarInfo*)varInfo;
    245 
    246   if (widget->isOption >= 1 && widget->isOption <= 3)
    247     {
    248       if (!strcmp (static_cast<Option*>(widget)->title, info->variableName))
     244void OrxonoxGuiExec::readFileText(Widget* widget, void* varInfo)
     245{
     246  VarInfo* info =(VarInfo*)varInfo;
     247
     248  if(widget->isOption >= 1 && widget->isOption <= 3)
     249    {
     250      if(!strcmp(static_cast<Option*>(widget)->title, info->variableName))
    249251        static_cast<Option*>(widget)->value = atoi(info->variableValue);
    250252    }
    251   else if (widget->isOption == 5)
    252     {
    253        if (!strcmp (static_cast<Option*>(widget)->title, info->variableName))
     253  else if(widget->isOption == 5)
     254    {
     255       if(!strcmp(static_cast<Option*>(widget)->title, info->variableName))
    254256        static_cast<OptionLabel*>(widget)->setValue(info->variableValue);
    255257    }
     
    262264   \param depth The Depth of the search seen from the first widget we searched from.
    263265   \returns The Widget that holds the Group, or the NULL if the Group wasn't found.
     266
     267   \todo do this in gui-gtk.
    264268*/
    265269Widget* OrxonoxGuiExec::locateGroup(Widget* widget, char* groupName, int depth)
     
    268272
    269273  // removes the trailing and ending [ ].
    270   if (!strncmp (groupName, "[", 1))
     274  if(!strncmp(groupName, "[", 1))
    271275    {
    272276      groupName = groupName+1;
     
    274278    }
    275279
    276   if (widget->isOption < 0)
    277     {
    278       if (static_cast<Packer*>(widget)->getGroupName() && !strcmp(groupName, static_cast<Packer*>(widget)->getGroupName()))
     280  if(widget->isOption < 0)
     281    {
     282      if(static_cast<Packer*>(widget)->getGroupName() && !strcmp(groupName, static_cast<Packer*>(widget)->getGroupName()))
    279283        {
    280284          return widget;
     
    282286      else
    283287        {
    284           if ((tmp = locateGroup (static_cast<Packer*>(widget)->down, groupName, depth+1)) != NULL)
     288          if((tmp = locateGroup(static_cast<Packer*>(widget)->down, groupName, depth+1)) != NULL)
    285289            return tmp;
    286290        }
    287291    }
    288292 
    289   if (widget->next != NULL && depth != 0)
    290     {
    291       if ((tmp = locateGroup (widget->next, groupName, depth)) != NULL)
     293  if(widget->next != NULL && depth != 0)
     294    {
     295      if((tmp = locateGroup(widget->next, groupName, depth)) != NULL)
    292296        return tmp;
    293297    }
     
    297301#ifdef HAVE_GTK2
    298302/**
    299    \brief Starts ORXONOX. (not really implemented yet, but the function is there.\n
     303   \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n
    300304   \param widget the widget that executed the start command
    301305   \param data additional data
     
    303307   This is a Signal and can be executed through Widget::signal_connect
    304308*/
    305 int OrxonoxGuiExec::startOrxonox (GtkWidget* widget, void* data)
    306 {
    307   OrxonoxGuiExec* exec = (OrxonoxGuiExec*)data;
    308   if (exec->shouldsave())
    309     exec->writeToFile (Window::mainWindow);
     309int OrxonoxGuiExec::startOrxonox(GtkWidget* widget, void* data)
     310{
     311  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
     312  if(exec->shouldsave())
     313    exec->writeToFile(Window::mainWindow);
    310314  cout << "Starting Orxonox" <<endl;
    311315  gtk_main_quit();
    312   system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real (coded not over the shell)
    313 }
    314 
    315 /**
    316    \brief Starts ORXONOX. (not really implemented yet, but the function is there.\n
     316  system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real(coded not over the shell)
     317}
     318
     319/**
     320   \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n
    317321   \param widget the widget that executed the start command
    318322   \param data additional data
     
    320324   This is a Signal and can be executed through Widget::signal_connect
    321325*/
    322 int OrxonoxGuiExec::quitOrxonox (GtkWidget* widget, void* data)
    323 {
    324   OrxonoxGuiExec* exec = (OrxonoxGuiExec*)data;
     326int OrxonoxGuiExec::quitOrxonox(GtkWidget* widget, void* data)
     327{
     328  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
    325329  PRINT(3)( "Quitting Orxonox %p\n", exec);
    326   if (exec->shouldsave())
    327     exec->writeToFile (Window::mainWindow);
     330  if(exec->shouldsave())
     331    exec->writeToFile(Window::mainWindow);
    328332  gtk_main_quit();
    329333}
    330334#else /* HAVE_GTK2 */
    331335/**
    332    \brief Starts ORXONOX. (not really implemented yet, but the function is there.\n
     336   \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n
    333337   \param widget the widget that executed the start command
    334338   \param data additional data
    335339*/
    336 int OrxonoxGuiExec::startOrxonox (void* widget, void* data)
    337 {
    338   OrxonoxGuiExec* exec = (OrxonoxGuiExec*)data;
     340int OrxonoxGuiExec::startOrxonox(void* widget, void* data)
     341{
     342  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
    339343  PRINT(3)("Starting Orxonox\n");
    340   if (exec->shouldsave())
    341     exec->writeToFile (Window::mainWindow);
    342   system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real (coded not over the shell)
     344  if(exec->shouldsave())
     345    exec->writeToFile(Window::mainWindow);
     346  system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real(coded not over the shell)
    343347}
    344348/**
     
    349353   This is a Signal and can be executed through Widget::signal_connect
    350354*/
    351 int OrxonoxGuiExec::quitOrxonox (void* widget, void* data)
    352 {
    353   OrxonoxGuiExec* exec = (OrxonoxGuiExec*)data;
     355int OrxonoxGuiExec::quitOrxonox(void* widget, void* data)
     356{
     357  OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data;
    354358  PRINT(3)("Quiting Orxonox");
    355   if (exec->shouldsave())
    356     exec->writeToFile (Window::mainWindow);
     359  if(exec->shouldsave())
     360    exec->writeToFile(Window::mainWindow);
    357361}
    358362
Note: See TracChangeset for help on using the changeset viewer.