Changeset 2707 in orxonox.OLD for orxonox/branches/buerli/gui/orxonox_gui_exec.cc
- Timestamp:
- Nov 3, 2004, 12:29:03 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/buerli/gui/orxonox_gui_exec.cc
r2595 r2707 38 38 execFrame = new Frame ("Execute-Tags:"); 39 39 execBox = new Box ('v'); 40 execFrame->setGroupName ("misc"); 40 41 41 42 start = new Button ("Start"); … … 109 110 CONFIG_FILE = fopen (configFile, "w"); 110 111 if (CONFIG_FILE) 111 writeFileText (widget );112 writeFileText (widget, 0); 112 113 fclose (CONFIG_FILE); 113 114 } … … 116 117 \brief Actually writes into the configuration file to the disk. 117 118 \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 */ 121 void 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 121 149 if (widget->is_option >= 1) 122 150 if (strcmp (static_cast<Option*>(widget)->flag_name, "") || strcmp (static_cast<Option*>(widget)->flag_name_short, "")) … … 124 152 char Buffer[256]; 125 153 char* space2under; 126 sprintf (Buffer, "%s", static_cast<Option*>(widget)-> option_name);154 sprintf (Buffer, "%s", static_cast<Option*>(widget)->label); 127 155 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; 129 157 while (space2under = strchr(Buffer, ' ')) 130 158 { … … 133 161 fprintf (CONFIG_FILE, "%s = %i\n", Buffer, static_cast<Option*>(widget)->value); 134 162 } 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 145 164 if (widget->next != NULL) 146 writeFileText (widget->next );165 writeFileText (widget->next, depth); 147 166 } 148 167 … … 156 175 if (CONFIG_FILE) 157 176 { 177 Widget* groupWidget = widget; 158 178 char Buffer[256] = ""; 159 179 char Variable[256]= ""; … … 161 181 while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF) 162 182 { 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 } 163 191 if (!strcmp (Buffer, "=")) 164 192 { … … 171 199 fscanf (CONFIG_FILE, "%s", Buffer); 172 200 Value = atoi(Buffer); 173 readFileText ( widget, Variable, Value);201 readFileText (groupWidget, Variable, Value, 0); 174 202 sprintf (Variable, ""); 175 203 } … … 179 207 } 180 208 } 181 182 209 /** 183 210 \brief Maps Confugurations to the Options. … … 185 212 \param variableName the name of the Variable that should be set up. 186 213 \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 */ 216 void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue, int depth) 189 217 { 190 218 if (widget->is_option >= 1) 191 if (!strcmp (static_cast<Option*>(widget)-> option_name, variableName))219 if (!strcmp (static_cast<Option*>(widget)->label, variableName)) 192 220 static_cast<Option*>(widget)->value = variableValue; 193 221 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); 202 225 } 203 226 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 */ 234 Widget* 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; 206 264 } 207 265
Note: See TracChangeset
for help on using the changeset viewer.