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