Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/gui: generalized: destructor, added label to class Widget, down is now a method of Packer, isOpen added for Windows

File size: 6.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19
20
21   ### File Specific:
22   main-programmer: Benjamin Grauer
23
24*/
25
26#include "orxonox_gui_exec.h"
27#include <iostream>
28#include <string>
29
30/**
31    \brief Creates the Exec-Frame
32    \param orxonoxGUI ExecFrame needs to know where to get the Options from
33*/
34OrxonoxGuiExec::OrxonoxGuiExec (Window* orxonoxGUI)
35{
36  configFile = (char*)malloc (512*sizeof (char));
37
38  execFrame = new Frame ("Execute-Tags:");
39  execBox = new Box ('v');
40 
41  start = new Button ("Start");
42  start->connectSignal ("clicked", startOrxonox);
43  execBox->fill (start);
44  saveSettings = new CheckButton ("Save Settings");
45  saveSettings->value = 1;
46  execBox->fill (saveSettings);
47  verboseMode = new Menu ("verbose mode", "no output", "verbose", "debug", "lastItem");
48  verboseMode->setFlagName ("verbose", "v", 0);
49  execBox->fill (verboseMode);
50  alwaysShow = new CheckButton ("Always Show this Menu");
51  alwaysShow->setFlagName ("gui", "g", 0);
52  execBox->fill (alwaysShow);
53  quit = new Button ("Quit");
54  quit->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit);
55  execBox->fill (quit);
56
57  execFrame->fill (execBox);
58}
59
60/**
61   \brief Return the Frame
62   \return Returns the Exec-frame
63*/
64Widget* OrxonoxGuiExec::getWidget ()
65{
66  return execFrame;
67}
68
69/* FILE HANDLING */
70
71/**
72   \brief Sets the location of the configuration File.\n
73   * The name will be parsed from ~/ to /home/[username] on unix and c:/Documents and Settings/username/Settings/ on Windows
74   \param filename the location of the configFile
75*/
76void OrxonoxGuiExec::setFilename (char* filename)
77{
78  char* buffer = (char*) malloc (512*sizeof(buffer));
79  sprintf (buffer, "%s", filename);
80  if (!strncmp (buffer, "~/", 2))
81  {
82#ifdef __WIN32__
83    sprintf (configFile, "%s/%s", getenv ("USERPROFILE"), buffer+2);
84#else
85    sprintf (configFile, "%s/%s", getenv ("HOME"), buffer+2);
86#endif
87  }
88  else if (buffer)
89    sprintf(configFile, "%s", buffer);
90  delete buffer;
91}
92
93/**
94   \brief checks if a option should be saved.
95   \return 1 if it should 0 if not/
96*/
97int OrxonoxGuiExec::shouldsave ()
98{
99  return ( static_cast<Option*>(saveSettings)->value);
100}
101
102/**
103    \brief Saves the configuration-file to the Disk.\n
104    this Function only opens and closes the file, in between OrxonoxGuiExec::writeFileText (Widget* widget) will execute the real writing process.
105    \param widget from which Widget on should be saved.
106*/
107void OrxonoxGuiExec::writeToFile (Widget* widget)
108{
109  CONFIG_FILE = fopen (configFile, "w");
110  if (CONFIG_FILE)
111    writeFileText (widget);
112  fclose (CONFIG_FILE);
113}
114
115/**
116   \brief Actually writes into the configuration file to the disk.
117   \param widget from which Widget on should be saved.
118*/
119void OrxonoxGuiExec::writeFileText (Widget* widget)
120{
121  if (widget->is_option >= 1)
122    if  (strcmp (static_cast<Option*>(widget)->flag_name, "") || strcmp (static_cast<Option*>(widget)->flag_name_short, ""))
123      {
124        char Buffer[256];
125        char* space2under;
126        sprintf (Buffer, "%s", static_cast<Option*>(widget)->label);
127        if (strchr (Buffer, '_'))
128          cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl; 
129        while (space2under = strchr(Buffer, ' '))
130          {
131            sprintf (space2under, "_%s", space2under+1);
132          }
133        fprintf (CONFIG_FILE, "%s = %i\n", Buffer, static_cast<Option*>(widget)->value);
134      }
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 
145  if (widget->next != NULL)
146    writeFileText (widget->next);
147}
148
149/**
150   \brief Reads in Configuration Data.
151   \param widget from which Widget on should be saved.
152*/
153void OrxonoxGuiExec::readFromFile (Widget* widget)
154{
155  CONFIG_FILE = fopen (configFile, "r");
156  if (CONFIG_FILE)
157    {
158      char Buffer[256] = "";
159      char Variable[256]= "";
160      int Value;
161      while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)
162        {
163          if (!strcmp (Buffer, "="))
164            {
165              char* under2space;
166              while (under2space = strchr(Variable, '_'))
167                {
168                  sprintf (under2space, " %s", under2space+1);
169                }
170             
171              fscanf (CONFIG_FILE, "%s", Buffer);
172              Value = atoi(Buffer);
173              readFileText (widget, Variable, Value);
174              sprintf (Variable, "");
175            }
176          sprintf (Variable, "%s", Buffer);
177        }
178      widget->walkThrough(widget->setOptions);
179    }
180}
181
182/**
183   \brief Maps Confugurations to the Options.
184   \param widget which widget downwards
185   \param variableName the name of the Variable that should be set up.
186   \param variableValue the Value of the Variable that should be set up
187*/
188void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue)
189{
190  if (widget->is_option >= 1)
191    if (!strcmp (static_cast<Option*>(widget)->label, variableName))
192        static_cast<Option*>(widget)->value = variableValue;
193
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;
202    } 
203
204  if (widget->next != NULL)
205    readFileText (widget->next, variableName, variableValue);
206}
207
208/**
209   \brief Starts ORXONOX. (not really implemented yet, but the function is there.\n
210   This is a Signal and can be executed through Widget::signal_connect
211   \param widget the widget that executed the start command
212   \param data additional data
213*/
214gint startOrxonox (GtkWidget *widget, Widget* data)
215{
216  cout << "Starting Orxonox" <<endl;
217}
Note: See TracBrowser for help on using the repository browser.