Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/gui/orxonox_gui_exec.cc @ 2053

Last change on this file since 2053 was 2053, checked in by bensch, 20 years ago

orxonox/trunk/gui: Now there is a possibility to start orxonox out of the gui.

File size: 3.9 KB
Line 
1#include "orxonox_gui_exec.h"
2#include <iostream>
3#include <string>
4
5OrxonoxGuiExec::OrxonoxGuiExec (Window* orxonoxGUI)
6{
7  configFile = (char*)malloc (512*sizeof (char));
8
9  execFrame = new Frame ("Execute-Tags:");
10  execBox = new Box ('v');
11 
12  start = new Button ("Start");
13  start->connectSignal ("clicked", startOrxonox);
14  execBox->fill (start);
15  saveSettings = new CheckButton ("Save Settings");
16  saveSettings->value = 1;
17  execBox->fill (saveSettings);
18  verboseMode = new Menu ("verbose mode", "no output", "verbose", "debug", "lastItem");
19  verboseMode->setFlagName ("verbose", "v", 0);
20  execBox->fill (verboseMode);
21  alwaysShow = new CheckButton ("Always Show this Menu");
22  alwaysShow->setFlagName ("gui", "g", 0);
23  execBox->fill (alwaysShow);
24  quit = new Button ("Quit");
25  quit->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit);
26  execBox->fill (quit);
27
28  execFrame->fill (execBox);
29}
30
31Frame* OrxonoxGuiExec::getFrame ()
32{
33  return execFrame;
34}
35
36/* FILE HANDLING */
37
38void OrxonoxGuiExec::setFilename (char* filename)
39{
40  char* buffer = (char*) malloc (512*sizeof(buffer));
41  sprintf (buffer, "%s", filename);
42  if (!strncmp (buffer, "~/", 2))
43  {
44#ifdef __WIN32__
45    sprintf (configFile, "%s/%s", getenv ("USERPROFILE"), buffer+2);
46#else
47    sprintf (configFile, "%s/%s", getenv ("HOME"), buffer+2);
48#endif
49  }
50  else if (buffer)
51    sprintf(configFile, "%s", buffer);
52  delete buffer;
53}
54
55int OrxonoxGuiExec::shouldsave ()
56{
57  return ( static_cast<Option*>(saveSettings)->value);
58}
59
60void OrxonoxGuiExec::writeToFile (Widget* widget)
61{
62  CONFIG_FILE = fopen (configFile, "w");
63  if (CONFIG_FILE)
64    writeFileText (widget);
65  fclose (CONFIG_FILE);
66}
67
68void OrxonoxGuiExec::writeFileText (Widget* widget)
69{
70  if (widget->is_option >= 1)
71    if  (strcmp (static_cast<Option*>(widget)->flag_name, "") || strcmp (static_cast<Option*>(widget)->flag_name_short, ""))
72      {
73        char Buffer[256];
74        char* space2under;
75        sprintf (Buffer, "%s", static_cast<Option*>(widget)->option_name);
76        if (strchr (Buffer, '_'))
77          cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl; 
78        while (space2under = strchr(Buffer, ' '))
79          {
80            sprintf (space2under, "_%s", space2under+1);
81          }
82        fprintf (CONFIG_FILE, "%s = %i\n", Buffer, static_cast<Option*>(widget)->value);
83      }
84  switch (widget->is_option)
85    {
86    case -1:
87      writeFileText (static_cast<Container*>(widget)->down);
88      break;
89    case -2:
90      writeFileText (static_cast<Box*>(widget)->down);
91      break;
92    } 
93 
94  if (widget->next != NULL)
95    writeFileText (widget->next);
96}
97
98void OrxonoxGuiExec::readFromFile (Widget* widget)
99{
100  CONFIG_FILE = fopen (configFile, "r");
101  if (CONFIG_FILE)
102    {
103      char Buffer[256] = "";
104      char Variable[256]= "";
105      int Value;
106      while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)
107        {
108          if (!strcmp (Buffer, "="))
109            {
110              char* under2space;
111              while (under2space = strchr(Variable, '_'))
112                {
113                  sprintf (under2space, " %s", under2space+1);
114                }
115             
116              fscanf (CONFIG_FILE, "%s", Buffer);
117              Value = atoi(Buffer);
118              readFileText (widget, Variable, Value);
119              sprintf (Variable, "");
120            }
121          sprintf (Variable, "%s", Buffer);
122        }
123      widget->setOptions();
124    }
125}
126
127void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue)
128{
129  if (widget->is_option >= 1)
130    if (!strcmp (static_cast<Option*>(widget)->option_name, variableName))
131        static_cast<Option*>(widget)->value = variableValue;
132
133  switch (widget->is_option)
134    {
135    case -1:
136      readFileText (static_cast<Container*>(widget)->down, variableName, variableValue);
137      break;
138    case -2:
139      readFileText (static_cast<Box*>(widget)->down, variableName, variableValue);
140      break;
141    } 
142
143  if (widget->next != NULL)
144    readFileText (widget->next, variableName, variableValue);
145}
146
147
148gint startOrxonox (GtkWidget *widget, Widget* data)
149{
150  /**
151   * Starts Orxonox.
152   */
153  cout << "Starting Orxonox" <<endl;
154}
Note: See TracBrowser for help on using the repository browser.