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