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