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