]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/panel_io.cxx
Make adf volume and adf on/off seperate properties.
[flightgear.git] / src / Cockpit / panel_io.cxx
1 //  panel_io.cxx - I/O for 2D panel.
2 //
3 //  Written by David Megginson, started January 2000.
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License as
7 //  published by the Free Software Foundation; either version 2 of the
8 //  License, or (at your option) any later version.
9 // 
10 //  This program is distributed in the hope that it will be useful, but
11 //  WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 //  General Public License for more details.
14 // 
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 //  $Id$
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #ifdef HAVE_WINDOWS_H          
26 #  include <windows.h>
27 #endif
28
29 #include <string.h>             // for strcmp()
30
31 #include <simgear/compiler.h>
32 #include <simgear/misc/exception.hxx>
33
34 #include <simgear/misc/sg_path.hxx>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/misc/props.hxx>
37
38 #include STL_IOSTREAM
39 #include STL_FSTREAM
40 #include STL_STRING
41
42 #include <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44
45 #include <GUI/gui.h>
46
47 #include "panel.hxx"
48 #include "panel_io.hxx"
49
50 //built-in layers
51 #include "built_in/FGMagRibbon.hxx"
52
53 #if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
54 SG_USING_STD(istream);
55 SG_USING_STD(ifstream);
56 #endif
57 SG_USING_STD(string);
58
59
60 \f
61 ////////////////////////////////////////////////////////////////////////
62 // Read and construct a panel.
63 //
64 // The panel is specified as a regular property list, and each of the
65 // instruments is its own, separate property list (and thus, a separate
66 // XML document).  The functions in this section read in the files
67 // as property lists, then extract properties to set up the panel
68 // itself.
69 //
70 // A panel contains zero or more instruments.
71 //
72 // An instrument contains one or more layers and zero or more actions.
73 //
74 // A layer contains zero or more transformations.
75 //
76 // Some special types of layers also contain other objects, such as 
77 // chunks of text or other layers.
78 //
79 // There are currently four types of layers:
80 //
81 // 1. Textured Layer (type="texture"), the default
82 // 2. Text Layer (type="text")
83 // 3. Switch Layer (type="switch")
84 // 4. Built-in Layer (type="built-in", must also specify class)
85 //
86 // The only built-in layer so far is the ribbon for the magnetic compass
87 // (class="compass-ribbon").
88 //
89 // There are three types of actions:
90 //
91 // 1. Adjust (type="adjust"), the default
92 // 2. Swap (type="swap")
93 // 3. Toggle (type="toggle")
94 //
95 // There are three types of transformations:
96 //
97 // 1. X shift (type="x-shift"), the default
98 // 2. Y shift (type="y-shift")
99 // 3. Rotation (type="rotation")
100 //
101 // Each of these may be associated with a property, so that a needle
102 // will rotate with the airspeed, for example, or may have a fixed
103 // floating-point value.
104 ////////////////////////////////////////////////////////////////////////
105
106
107 /**
108  * Read a cropped texture from the instrument's property list.
109  *
110  * The x1 and y1 properties give the starting position of the texture
111  * (between 0.0 and 1.0), and the the x2 and y2 properties give the
112  * ending position.  For example, to use the bottom-left quarter of a
113  * texture, x1=0.0, y1=0.0, x2=0.5, y2=0.5.
114  */
115 static FGCroppedTexture
116 readTexture (const SGPropertyNode * node)
117 {
118     FGCroppedTexture texture(node->getStringValue("path"),
119                              node->getFloatValue("x1"),
120                              node->getFloatValue("y1"),
121                              node->getFloatValue("x2", 1.0),
122                              node->getFloatValue("y2", 1.0));
123     SG_LOG(SG_COCKPIT, SG_DEBUG, "Read texture " << node->getName());
124     return texture;
125 }
126
127
128 /**
129  * Test for a condition in the current node.
130  */
131 \f
132 ////////////////////////////////////////////////////////////////////////
133 // Read a condition and use it if necessary.
134 ////////////////////////////////////////////////////////////////////////
135
136 static void
137 readConditions (FGConditional * component, const SGPropertyNode * node)
138 {
139   const SGPropertyNode * conditionNode = node->getChild("condition");
140   if (conditionNode != 0)
141                                 // The top level is implicitly AND
142     component->setCondition(fgReadCondition(conditionNode));
143 }
144
145
146 /**
147  * Read an action from the instrument's property list.
148  *
149  * The action will be performed when the user clicks a mouse button
150  * within the specified region of the instrument.  Actions always work
151  * by modifying the value of a property (see the SGPropertyNode
152  * class).
153  *
154  * The following action types are defined:
155  *
156  * "adjust" - modify the value of a floating-point property by
157  *    the increment specified.  This is the default.
158  *
159  * "swap" - swap the values of two-floating-point properties.
160  *
161  * "toggle" - toggle the value of a boolean property between true and
162  *    false.
163  *
164  * For the adjust action, it is possible to specify an increment
165  * (use a negative number for a decrement), a minimum allowed value,
166  * a maximum allowed value, and a flag to indicate whether the value
167  * should freeze or wrap-around when it reachs the minimum or maximum.
168  *
169  * The action will be scaled automatically if the instrument is not
170  * being drawn at its regular size.
171  */
172 static FGPanelAction *
173 readAction (const SGPropertyNode * node, float w_scale, float h_scale)
174 {
175   string name = node->getStringValue("name");
176
177   int button = node->getIntValue("button");
178   int x = int(node->getIntValue("x") * w_scale);
179   int y = int(node->getIntValue("y") * h_scale);
180   int w = int(node->getIntValue("w") * w_scale);
181   int h = int(node->getIntValue("h") * h_scale);
182
183   FGPanelAction * action = new FGPanelAction(button, x, y, w, h);
184
185   vector<SGPropertyNode_ptr>bindings = node->getChildren("binding");
186   for (unsigned int i = 0; i < bindings.size(); i++) {
187     SG_LOG(SG_INPUT, SG_INFO, "Reading binding "
188            << bindings[i]->getStringValue("command"));
189     action->addBinding(new FGBinding(bindings[i])); // TODO: allow modifiers
190   }
191
192   readConditions(action, node);
193   return action;
194 }
195
196
197 /**
198  * Read a transformation from the instrument's property list.
199  *
200  * The panel module uses the transformations to slide or spin needles,
201  * knobs, and other indicators, and to place layers in the correct
202  * positions.  Every layer starts centered exactly on the x,y co-ordinate,
203  * and many layers need to be moved or rotated simply to display the
204  * instrument correctly.
205  *
206  * There are three types of transformations:
207  *
208  * "x-shift" - move the layer horizontally.
209  *
210  * "y-shift" - move the layer vertically.
211  *
212  * "rotation" - rotate the layer.
213  *
214  * Each transformation may have a fixed offset, and may also have
215  * a floating-point property value to add to the offset.  The
216  * floating-point property may be clamped to a minimum and/or
217  * maximum range and scaled (after clamping).
218  *
219  * Note that because of the way OpenGL works, transformations will
220  * appear to be applied backwards.
221  */
222 static FGPanelTransformation *
223 readTransformation (const SGPropertyNode * node, float w_scale, float h_scale)
224 {
225   FGPanelTransformation * t = new FGPanelTransformation;
226
227   string name = node->getName();
228   string type = node->getStringValue("type");
229   string propName = node->getStringValue("property", "");
230   SGPropertyNode * target = 0;
231
232   if (type.empty()) {
233     SG_LOG( SG_COCKPIT, SG_ALERT,
234             "No type supplied for transformation " << name
235             << " assuming \"rotation\"" );
236     type = "rotation";
237   }
238
239   if (!propName.empty()) {
240     target = fgGetNode(propName.c_str(), true);
241   }
242
243   t->node = target;
244   t->min = node->getFloatValue("min", -9999999);
245   t->max = node->getFloatValue("max", 99999999);
246   t->factor = node->getFloatValue("scale", 1.0);
247   t->offset = node->getFloatValue("offset", 0.0);
248
249                                 // Check for an interpolation table
250   const SGPropertyNode * trans_table = node->getNode("interpolation");
251   if (trans_table != 0) {
252     SG_LOG( SG_COCKPIT, SG_INFO, "Found interpolation table with "
253             << trans_table->nChildren() << "children" );
254     t->table = new SGInterpTable();
255     for(int i = 0; i < trans_table->nChildren(); i++) {
256       const SGPropertyNode * node = trans_table->getChild(i);
257       if (!strcmp(node->getName(), "entry")) {
258         double ind = node->getDoubleValue("ind", 0.0);
259         double dep = node->getDoubleValue("dep", 0.0);
260         SG_LOG( SG_COCKPIT, SG_INFO, "Adding interpolation entry "
261                 << ind << "==>" << dep );
262         t->table->addEntry(ind, dep);
263       } else {
264         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
265                 << " in interpolation" );
266       }
267     }
268   } else {
269     t->table = 0;
270   }
271   
272                                 // Move the layer horizontally.
273   if (type == "x-shift") {
274     t->type = FGPanelTransformation::XSHIFT;
275 //     t->min *= w_scale; //removed by Martin Dressler
276 //     t->max *= w_scale; //removed by Martin Dressler
277     t->offset *= w_scale;
278     t->factor *= w_scale; //Added by Martin Dressler
279   } 
280
281                                 // Move the layer vertically.
282   else if (type == "y-shift") {
283     t->type = FGPanelTransformation::YSHIFT;
284     //t->min *= h_scale; //removed
285     //t->max *= h_scale; //removed
286     t->offset *= h_scale;
287     t->factor *= h_scale; //Added
288   } 
289
290                                 // Rotate the layer.  The rotation
291                                 // is in degrees, and does not need
292                                 // to scale with the instrument size.
293   else if (type == "rotation") {
294     t->type = FGPanelTransformation::ROTATION;
295   } 
296
297   else {
298     SG_LOG( SG_COCKPIT, SG_ALERT, "Unrecognized transformation type " << type );
299     delete t;
300     return 0;
301   }
302
303   readConditions(t, node);
304   SG_LOG( SG_COCKPIT, SG_DEBUG, "Read transformation " << name );
305   return t;
306 }
307
308
309 /**
310  * Read a chunk of text from the instrument's property list.
311  *
312  * A text layer consists of one or more chunks of text.  All chunks
313  * share the same font size and color (and eventually, font), but
314  * each can come from a different source.  There are three types of
315  * text chunks:
316  *
317  * "literal" - a literal text string (the default)
318  *
319  * "text-value" - the current value of a string property
320  *
321  * "number-value" - the current value of a floating-point property.
322  *
323  * All three may also include a printf-style format string.
324  */
325 FGTextLayer::Chunk *
326 readTextChunk (const SGPropertyNode * node)
327 {
328   FGTextLayer::Chunk * chunk;
329   string name = node->getStringValue("name");
330   string type = node->getStringValue("type");
331   string format = node->getStringValue("format");
332
333                                 // Default to literal text.
334   if (type.empty()) {
335     SG_LOG( SG_COCKPIT, SG_INFO, "No type provided for text chunk " << name
336             << " assuming \"literal\"");
337     type = "literal";
338   }
339
340                                 // A literal text string.
341   if (type == "literal") {
342     string text = node->getStringValue("text");
343     chunk = new FGTextLayer::Chunk(text, format);
344   }
345
346                                 // The value of a string property.
347   else if (type == "text-value") {
348     SGPropertyNode * target =
349       fgGetNode(node->getStringValue("property"), true);
350     chunk = new FGTextLayer::Chunk(FGTextLayer::TEXT_VALUE, target, format);
351   }
352
353                                 // The value of a float property.
354   else if (type == "number-value") {
355     string propName = node->getStringValue("property");
356     float scale = node->getFloatValue("scale", 1.0);
357     SGPropertyNode * target = fgGetNode(propName.c_str(), true);
358     chunk = new FGTextLayer::Chunk(FGTextLayer::DOUBLE_VALUE, target,
359                                    format, scale);
360   }
361
362                                 // Unknown type.
363   else {
364     SG_LOG( SG_COCKPIT, SG_ALERT, "Unrecognized type " << type
365             << " for text chunk " << name );
366     return 0;
367   }
368
369   readConditions(chunk, node);
370   return chunk;
371 }
372
373
374 /**
375  * Read a single layer from an instrument's property list.
376  *
377  * Each instrument consists of one or more layers stacked on top
378  * of each other; the lower layers show through only where the upper
379  * layers contain an alpha component.  Each layer can be moved
380  * horizontally and vertically and rotated using transformations.
381  *
382  * This module currently recognizes four kinds of layers:
383  *
384  * "texture" - a layer containing a texture (the default)
385  *
386  * "text" - a layer containing text
387  *
388  * "switch" - a layer that switches between two other layers
389  *   based on the current value of a boolean property.
390  *
391  * "built-in" - a hard-coded layer supported by C++ code in FlightGear.
392  *
393  * Currently, the only built-in layer class is "compass-ribbon".
394  */
395 static FGInstrumentLayer *
396 readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
397 {
398   FGInstrumentLayer * layer = NULL;
399   string name = node->getStringValue("name");
400   string type = node->getStringValue("type");
401   int w = node->getIntValue("w", -1);
402   int h = node->getIntValue("h", -1);
403   if (w != -1)
404     w = int(w * w_scale);
405   if (h != -1)
406     h = int(h * h_scale);
407
408
409   if (type.empty()) {
410     SG_LOG( SG_COCKPIT, SG_ALERT,
411             "No type supplied for layer " << name
412             << " assuming \"texture\"" );
413     type = "texture";
414   }
415
416
417                                 // A textured instrument layer.
418   if (type == "texture") {
419     FGCroppedTexture texture = readTexture(node->getNode("texture"));
420     layer = new FGTexturedLayer(texture, w, h);
421   }
422
423                                 // A group of sublayers.
424   else if (type == "group") {
425     layer = new FGGroupLayer();
426     for (int i = 0; i < node->nChildren(); i++) {
427       const SGPropertyNode * child = node->getChild(i);
428       cerr << "Trying child " << child->getName() << endl;
429       if (!strcmp(child->getName(), "layer")) {
430         cerr << "succeeded!" << endl;
431         ((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
432       }
433     }
434   }
435
436
437                                 // A textual instrument layer.
438   else if (type == "text") {
439     FGTextLayer * tlayer = new FGTextLayer(w, h); // FIXME
440
441                                 // Set the text color.
442     float red = node->getFloatValue("color/red", 0.0);
443     float green = node->getFloatValue("color/green", 0.0);
444     float blue = node->getFloatValue("color/blue", 0.0);
445     tlayer->setColor(red, green, blue);
446
447                                 // Set the point size.
448     float pointSize = node->getFloatValue("point-size", 10.0) * w_scale;
449     tlayer->setPointSize(pointSize);
450
451                                 // Set the font.
452     string fontName = node->getStringValue("font", "default");
453     tlayer->setFontName(fontName);
454
455     const SGPropertyNode * chunk_group = node->getNode("chunks");
456     if (chunk_group != 0) {
457       int nChunks = chunk_group->nChildren();
458       for (int i = 0; i < nChunks; i++) {
459         const SGPropertyNode * node = chunk_group->getChild(i);
460         if (!strcmp(node->getName(), "chunk")) {
461           FGTextLayer::Chunk * chunk = readTextChunk(node);
462           if (chunk != 0)
463             tlayer->addChunk(chunk);
464         } else {
465           SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
466                   << " in chunks" );
467         }
468       }
469       layer = tlayer;
470     }
471   }
472
473                                 // A switch instrument layer.
474   else if (type == "switch") {
475     SGPropertyNode * target =
476       fgGetNode(node->getStringValue("property"), true);
477     FGInstrumentLayer * layer1 =
478       readLayer(node->getNode("layer[0]"), w_scale, h_scale);
479     FGInstrumentLayer * layer2 =
480       readLayer(node->getNode("layer[1]"), w_scale, h_scale);
481     layer = new FGSwitchLayer(w, h, target, layer1, layer2);
482   }
483
484                                 // A built-in instrument layer.
485   else if (type == "built-in") {
486     string layerclass = node->getStringValue("class");
487
488     if (layerclass == "mag-ribbon") {
489       layer = new FGMagRibbon(w, h);
490     }
491
492     else if (layerclass.empty()) {
493       SG_LOG( SG_COCKPIT, SG_ALERT, "No class provided for built-in layer "
494               << name );
495       return 0;
496     }
497
498     else {
499       SG_LOG( SG_COCKPIT, SG_ALERT, "Unknown built-in layer class "
500               << layerclass);
501       return 0;
502     }
503   }
504
505                                 // An unknown type.
506   else {
507     SG_LOG( SG_COCKPIT, SG_ALERT, "Unrecognized layer type " << type );
508     delete layer;
509     return 0;
510   }
511   
512   //
513   // Get the transformations for each layer.
514   //
515   const SGPropertyNode * trans_group = node->getNode("transformations");
516   if (trans_group != 0) {
517     int nTransformations = trans_group->nChildren();
518     for (int i = 0; i < nTransformations; i++) {
519       const SGPropertyNode * node = trans_group->getChild(i);
520       if (!strcmp(node->getName(), "transformation")) {
521         FGPanelTransformation * t = readTransformation(node, w_scale, h_scale);
522         if (t != 0)
523           layer->addTransformation(t);
524       } else {
525         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
526                 << " in transformations" );
527       }
528     }
529   }
530
531   readConditions(layer, node);
532   SG_LOG( SG_COCKPIT, SG_DEBUG, "Read layer " << name );
533   return layer;
534 }
535
536
537 /**
538  * Read an instrument from a property list.
539  *
540  * The instrument consists of a preferred width and height
541  * (the panel may override these), together with a list of layers
542  * and a list of actions to be performed when the user clicks 
543  * the mouse over the instrument.  All co-ordinates are relative
544  * to the instrument's position, so instruments are fully relocatable;
545  * likewise, co-ordinates for actions and transformations will be
546  * scaled automatically if the instrument is not at its preferred size.
547  */
548 static FGPanelInstrument *
549 readInstrument (const SGPropertyNode * node)
550 {
551   const string name = node->getStringValue("name");
552   int x = node->getIntValue("x", -1);
553   int y = node->getIntValue("y", -1);
554   int real_w = node->getIntValue("w", -1);
555   int real_h = node->getIntValue("h", -1);
556   int w = node->getIntValue("w-base", -1);
557   int h = node->getIntValue("h-base", -1);
558
559   if (x == -1 || y == -1) {
560     SG_LOG( SG_COCKPIT, SG_ALERT,
561             "x and y positions must be specified and > 0" );
562     return 0;
563   }
564
565   float w_scale = 1.0;
566   float h_scale = 1.0;
567   if (real_w != -1) {
568     w_scale = float(real_w) / float(w);
569     w = real_w;
570   }
571   if (real_h != -1) {
572     h_scale = float(real_h) / float(h);
573     h = real_h;
574   }
575
576   SG_LOG( SG_COCKPIT, SG_DEBUG, "Reading instrument " << name );
577
578   FGLayeredInstrument * instrument =
579     new FGLayeredInstrument(x, y, w, h);
580
581   //
582   // Get the actions for the instrument.
583   //
584   const SGPropertyNode * action_group = node->getNode("actions");
585   if (action_group != 0) {
586     int nActions = action_group->nChildren();
587     for (int i = 0; i < nActions; i++) {
588       const SGPropertyNode * node = action_group->getChild(i);
589       if (!strcmp(node->getName(), "action")) {
590         FGPanelAction * action = readAction(node, w_scale, h_scale);
591         if (action != 0)
592           instrument->addAction(action);
593       } else {
594         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
595                 << " in actions" );
596       }
597     }
598   }
599
600   //
601   // Get the layers for the instrument.
602   //
603   const SGPropertyNode * layer_group = node->getNode("layers");
604   if (layer_group != 0) {
605     int nLayers = layer_group->nChildren();
606     for (int i = 0; i < nLayers; i++) {
607       const SGPropertyNode * node = layer_group->getChild(i);
608       if (!strcmp(node->getName(), "layer")) {
609         FGInstrumentLayer * layer = readLayer(node, w_scale, h_scale);
610         if (layer != 0)
611           instrument->addLayer(layer);
612       } else {
613         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
614                 << " in layers" );
615       }
616     }
617   }
618
619   readConditions(instrument, node);
620   SG_LOG( SG_COCKPIT, SG_DEBUG, "Done reading instrument " << name );
621   return instrument;
622 }
623
624
625 /**
626  * Construct the panel from a property tree.
627  */
628 FGPanel *
629 readPanel (const SGPropertyNode * root)
630 {
631   SG_LOG( SG_COCKPIT, SG_INFO, "Reading properties for panel " <<
632           root->getStringValue("name", "[Unnamed Panel]") );
633
634   FGPanel * panel = new FGPanel();
635   panel->setWidth(root->getIntValue("w", 1024));
636   panel->setHeight(root->getIntValue("h", 443));
637
638   //
639   // Grab the visible external viewing area, default to 
640   //
641   panel->setViewHeight(root->getIntValue("view-height",
642                                          768 - panel->getHeight() + 2));
643
644   //
645   // Grab the panel's initial offsets, default to 0, 0.
646   //
647   if (!fgHasNode("/sim/panel/x-offset"))
648     fgSetInt("/sim/panel/x-offset", root->getIntValue("x-offset", 0));
649
650   // conditional removed by jim wilson to allow panel xml code 
651   // with y-offset defined to work...
652   if (!fgHasNode("/sim/panel/y-offset"))
653     fgSetInt("/sim/panel/y-offset", root->getIntValue("y-offset", 0));
654
655   //
656   // Assign the background texture, if any, or a bogus chequerboard.
657   //
658   string bgTexture = root->getStringValue("background");
659   if (bgTexture.empty())
660     bgTexture = "FOO";
661   panel->setBackground(FGTextureManager::createTexture(bgTexture.c_str()));
662   SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << bgTexture );
663
664   //
665   // Get multibackground if any...
666   //
667   string mbgTexture = root->getStringValue("multibackground[0]");
668   if (!mbgTexture.empty()) {
669     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 0);
670     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
671
672     mbgTexture = root->getStringValue("multibackground[1]");
673     if (mbgTexture.empty())
674       mbgTexture = "FOO";
675     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 1);
676     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
677
678     mbgTexture = root->getStringValue("multibackground[2]");
679     if (mbgTexture.empty())
680       mbgTexture = "FOO";
681     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 2);
682     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
683
684     mbgTexture = root->getStringValue("multibackground[3]");
685     if (mbgTexture.empty())
686       mbgTexture = "FOO";
687     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 3);
688     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
689
690     mbgTexture = root->getStringValue("multibackground[4]");
691     if (mbgTexture.empty())
692       mbgTexture = "FOO";
693     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 4);
694     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
695
696     mbgTexture = root->getStringValue("multibackground[5]");
697     if (mbgTexture.empty())
698       mbgTexture = "FOO";
699     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 5);
700     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
701
702     mbgTexture = root->getStringValue("multibackground[6]");
703     if (mbgTexture.empty())
704       mbgTexture = "FOO";
705     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 6);
706     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
707
708     mbgTexture = root->getStringValue("multibackground[7]");
709     if (mbgTexture.empty())
710       mbgTexture = "FOO";
711     panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 7);
712     SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
713
714   }
715   
716
717
718   //
719   // Create each instrument.
720   //
721   SG_LOG( SG_COCKPIT, SG_INFO, "Reading panel instruments" );
722   const SGPropertyNode * instrument_group = root->getChild("instruments");
723   if (instrument_group != 0) {
724     int nInstruments = instrument_group->nChildren();
725     for (int i = 0; i < nInstruments; i++) {
726       const SGPropertyNode * node = instrument_group->getChild(i);
727       if (!strcmp(node->getName(), "instrument")) {
728         FGPanelInstrument * instrument = readInstrument(node);
729         if (instrument != 0)
730           panel->addInstrument(instrument);
731       } else {
732         SG_LOG( SG_COCKPIT, SG_INFO, "Skipping " << node->getName()
733                 << " in instruments section" );
734       }
735     }
736   }
737   SG_LOG( SG_COCKPIT, SG_INFO, "Done reading panel instruments" );
738
739
740   //
741   // Return the new panel.
742   //
743   return panel;
744 }
745
746
747 /**
748  * Read a panel from a property list.
749  *
750  * Each panel instrument will appear in its own, separate
751  * property list.  The top level simply names the panel and
752  * places the instruments in their appropriate locations (and
753  * optionally resizes them if necessary).
754  *
755  * Returns 0 if the read fails for any reason.
756  */
757 FGPanel *
758 fgReadPanel (istream &input)
759 {
760   SGPropertyNode root;
761
762   try {
763     readProperties(input, &root);
764   } catch (const sg_exception &e) {
765     guiErrorMessage("Error reading panel: ", e);
766     return 0;
767   }
768   return readPanel(&root);
769 }
770
771
772 /**
773  * Read a panel from a property list.
774  *
775  * This function opens a stream to a file, then invokes the
776  * main fgReadPanel() function.
777  */
778 FGPanel *
779 fgReadPanel (const string &relative_path)
780 {
781   SGPath path(globals->get_fg_root());
782   path.append(relative_path);
783   SGPropertyNode root;
784
785   try {
786     readProperties(path.str(), &root);
787   } catch (const sg_exception &e) {
788     guiErrorMessage("Error reading panel: ", e);
789     return 0;
790   }
791   return readPanel(&root);
792 }
793
794
795
796 // end of panel_io.cxx
797
798
799