Changeset 3315 in orxonox.OLD for orxonox/branches/updater/src/gui/orxonox_gui_exec.cc
- Timestamp:
- Jan 3, 2005, 12:13:38 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/updater/src/gui/orxonox_gui_exec.cc
r3301 r3315 34 34 \param orxonoxGUI ExecFrame needs to know where to get the Options from 35 35 */ 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");36 OrxonoxGuiExec::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"); 43 43 44 start = new Button("Start");44 this->start = new Button("Start"); 45 45 #ifdef HAVE_GTK2 46 start->connectSignal("clicked", this, startOrxonox);46 this->start->connectSignal("clicked", this, startOrxonox); 47 47 #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"); 62 62 #ifdef HAVE_GTK2 63 quit->connectSignal("clicked", this, OrxonoxGuiExec::quitOrxonox);64 orxonoxGUI->connectSignal("destroy", this, OrxonoxGuiExec::quitOrxonox);65 //! orxonoxGUI->connectSignal 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. 66 66 #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); 70 70 } 71 71 … … 74 74 \return Returns the Exec-frame 75 75 */ 76 Widget* OrxonoxGuiExec::getWidget ()76 Widget* OrxonoxGuiExec::getWidget(void) 77 77 { 78 78 return execFrame; … … 85 85 \param filename the location of the configFile 86 86 87 \todo: memory allocation could be better. 88 87 89 The name will be parsed from ~/ to /home/[username] on unix and c:/Documents and Settings/username/Settings/ on Windows 88 90 */ 89 void OrxonoxGuiExec::setFilename 90 { 91 char* buffer = (char*) malloc (512*sizeof(buffer));92 sprintf 93 if (!strncmp(buffer, "~/", 2))91 void OrxonoxGuiExec::setFilename(char* filename) 92 { 93 char* buffer = (char*)malloc(2048*sizeof(char)); 94 sprintf(buffer, "%s", filename); 95 if(!strncmp(buffer, "~/", 2)) 94 96 { 95 97 #ifdef __WIN32__ 96 sprintf (configFile, "%s/%s", getenv("USERPROFILE"), buffer+2);98 sprintf(configFile, "%s/%s", getenv("USERPROFILE"), buffer+2); 97 99 #else 98 sprintf (configFile, "%s/%s", getenv("HOME"), buffer+2);100 sprintf(configFile, "%s/%s", getenv("HOME"), buffer+2); 99 101 #endif 100 102 } 101 else if 102 s printf(configFile, "%s", buffer);103 delete buffer;103 else if(buffer) 104 strcpy(this->configFile, buffer); 105 free (buffer); 104 106 } 105 107 … … 109 111 char* OrxonoxGuiExec::getConfigFile(void) 110 112 { 111 return configFile;113 return this->configFile; 112 114 } 113 115 … … 116 118 \return 1 if it should 0 if not/ 117 119 */ 118 int OrxonoxGuiExec::shouldsave 119 { 120 return (static_cast<Option*>(saveSettings)->value);120 int OrxonoxGuiExec::shouldsave() 121 { 122 return(static_cast<Option*>(this->saveSettings)->value); 121 123 } 122 124 … … 125 127 \param widget from which Widget on should be saved. 126 128 127 this Function only opens and closes the file, in between OrxonoxGuiExec::writeFileText 128 */ 129 void OrxonoxGuiExec::writeToFile 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 */ 131 void 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); 135 137 } 136 138 … … 140 142 \param depth initially "0", and grows higher, while new Groups are bundeled. 141 143 */ 142 void OrxonoxGuiExec::writeFileText 144 void OrxonoxGuiExec::writeFileText(Widget* widget, int depth) 143 145 { 144 146 int counter = 0; 145 while (counter < depth &&((widget->isOption>0146 && 147 || 147 while(counter < depth &&((widget->isOption>0 148 &&(static_cast<Option*>(widget)->isSaveable()) ) 149 ||(widget->isOption<0 148 150 && static_cast<Packer*>(widget)->getGroupName()))) 149 151 { 150 fprintf (CONFIG_FILE, " ", depth);152 fprintf(this->CONFIG_FILE, " ", depth); 151 153 counter++; 152 154 } 153 155 154 156 // 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 156 { 157 if 158 { 159 fprintf 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); 161 163 fprintf(CONFIG_FILE, "\n"); 162 164 } 163 165 else 164 166 { 165 writeFileText(static_cast<Packer*>(widget)->down, depth);167 this->writeFileText(static_cast<Packer*>(widget)->down, depth); 166 168 } 167 169 } 168 // if 169 // printf 170 if 171 if 170 // if(widget->isOption == 0) 171 // printf("%s\n",widget->title); 172 if(widget->isOption >= 1) 173 if (static_cast<Option*>(widget)->isSaveable()) 172 174 { 173 175 char Buffer[256]; 174 176 char* space2under; 175 strcpy 176 if (strchr(Buffer, '_'))177 strcpy(Buffer, static_cast<Option*>(widget)->title); 178 if(strchr(Buffer, '_')) 177 179 cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl; 178 while 180 while(space2under = strchr(Buffer, ' ')) 179 181 { 180 182 space2under[0] = '_'; 181 183 } 182 if 183 fprintf 184 else if 185 fprintf 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); 186 188 } 187 189 188 if 189 writeFileText(widget->next, depth);190 if(widget->next != NULL) 191 this->writeFileText(widget->next, depth); 190 192 } 191 193 … … 194 196 \param widget from which Widget on should be saved. 195 197 */ 196 void OrxonoxGuiExec::readFromFile 197 { 198 CONFIG_FILE = fopen(configFile, "r");198 void OrxonoxGuiExec::readFromFile(Widget* widget) 199 { 200 this->CONFIG_FILE = fopen(configFile, "r"); 199 201 VarInfo varInfo; 200 if (CONFIG_FILE)202 if(this->CONFIG_FILE) 201 203 { 202 204 Widget* groupWidget = widget; … … 204 206 char Variable[256]= ""; 205 207 char* Value; 206 while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)208 while(fscanf(this->CONFIG_FILE, "%s", Buffer) != EOF) 207 209 { 208 210 // group-search // 209 if (!strncmp(Buffer, "[", 1))211 if(!strncmp(Buffer, "[", 1)) 210 212 { 211 if ((groupWidget = locateGroup(widget, Buffer, 1))==NULL)213 if((groupWidget = locateGroup(widget, Buffer, 1))==NULL) 212 214 { 213 215 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"; … … 216 218 } 217 219 // option-setting // 218 if (!strcmp(Buffer, "="))220 if(!strcmp(Buffer, "=")) 219 221 { 220 222 char* under2space; 221 while 223 while(under2space = strchr(Variable, '_')) 222 224 { 223 sprintf 225 sprintf(under2space, " %s", under2space+1); 224 226 } 225 227 226 fscanf (CONFIG_FILE, "%s", Buffer);228 fscanf(this->CONFIG_FILE, "%s", Buffer); 227 229 varInfo.variableName = Variable; 228 230 varInfo.variableValue = Buffer; 229 groupWidget->walkThrough( readFileText, &varInfo, 0);230 sprintf 231 groupWidget->walkThrough(this->readFileText, &varInfo, 0); 232 sprintf(Variable, ""); 231 233 } 232 sprintf 234 sprintf(Variable, "%s", Buffer); 233 235 } 234 236 widget->walkThrough(widget->setOptions, 0); … … 240 242 \param varInfo Information about the Variable to read 241 243 */ 242 void OrxonoxGuiExec::readFileText 243 { 244 VarInfo* info = 245 246 if 247 { 248 if (!strcmp(static_cast<Option*>(widget)->title, info->variableName))244 void 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)) 249 251 static_cast<Option*>(widget)->value = atoi(info->variableValue); 250 252 } 251 else if 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)) 254 256 static_cast<OptionLabel*>(widget)->setValue(info->variableValue); 255 257 } … … 262 264 \param depth The Depth of the search seen from the first widget we searched from. 263 265 \returns The Widget that holds the Group, or the NULL if the Group wasn't found. 266 267 \todo do this in gui-gtk. 264 268 */ 265 269 Widget* OrxonoxGuiExec::locateGroup(Widget* widget, char* groupName, int depth) … … 268 272 269 273 // removes the trailing and ending [ ]. 270 if (!strncmp(groupName, "[", 1))274 if(!strncmp(groupName, "[", 1)) 271 275 { 272 276 groupName = groupName+1; … … 274 278 } 275 279 276 if 277 { 278 if 280 if(widget->isOption < 0) 281 { 282 if(static_cast<Packer*>(widget)->getGroupName() && !strcmp(groupName, static_cast<Packer*>(widget)->getGroupName())) 279 283 { 280 284 return widget; … … 282 286 else 283 287 { 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) 285 289 return tmp; 286 290 } 287 291 } 288 292 289 if 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) 292 296 return tmp; 293 297 } … … 297 301 #ifdef HAVE_GTK2 298 302 /** 299 \brief Starts ORXONOX. 303 \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n 300 304 \param widget the widget that executed the start command 301 305 \param data additional data … … 303 307 This is a Signal and can be executed through Widget::signal_connect 304 308 */ 305 int OrxonoxGuiExec::startOrxonox 306 { 307 OrxonoxGuiExec* exec = 308 if 309 exec->writeToFile 309 int OrxonoxGuiExec::startOrxonox(GtkWidget* widget, void* data) 310 { 311 OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data; 312 if(exec->shouldsave()) 313 exec->writeToFile(Window::mainWindow); 310 314 cout << "Starting Orxonox" <<endl; 311 315 gtk_main_quit(); 312 system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real 313 } 314 315 /** 316 \brief Starts ORXONOX. 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 317 321 \param widget the widget that executed the start command 318 322 \param data additional data … … 320 324 This is a Signal and can be executed through Widget::signal_connect 321 325 */ 322 int OrxonoxGuiExec::quitOrxonox 323 { 324 OrxonoxGuiExec* exec = 326 int OrxonoxGuiExec::quitOrxonox(GtkWidget* widget, void* data) 327 { 328 OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data; 325 329 PRINT(3)( "Quitting Orxonox %p\n", exec); 326 if 327 exec->writeToFile 330 if(exec->shouldsave()) 331 exec->writeToFile(Window::mainWindow); 328 332 gtk_main_quit(); 329 333 } 330 334 #else /* HAVE_GTK2 */ 331 335 /** 332 \brief Starts ORXONOX. 336 \brief Starts ORXONOX.(not really implemented yet, but the function is there.\n 333 337 \param widget the widget that executed the start command 334 338 \param data additional data 335 339 */ 336 int OrxonoxGuiExec::startOrxonox 337 { 338 OrxonoxGuiExec* exec = 340 int OrxonoxGuiExec::startOrxonox(void* widget, void* data) 341 { 342 OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data; 339 343 PRINT(3)("Starting Orxonox\n"); 340 if 341 exec->writeToFile 342 system("cd ..;./orxonox"); //!< \todo fix this. should execute orxonox for real 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) 343 347 } 344 348 /** … … 349 353 This is a Signal and can be executed through Widget::signal_connect 350 354 */ 351 int OrxonoxGuiExec::quitOrxonox 352 { 353 OrxonoxGuiExec* exec = 355 int OrxonoxGuiExec::quitOrxonox(void* widget, void* data) 356 { 357 OrxonoxGuiExec* exec =(OrxonoxGuiExec*)data; 354 358 PRINT(3)("Quiting Orxonox"); 355 if 356 exec->writeToFile 359 if(exec->shouldsave()) 360 exec->writeToFile(Window::mainWindow); 357 361 } 358 362
Note: See TracChangeset
for help on using the changeset viewer.