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