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