Plot2D_OptionFile.cpp

Go to the documentation of this file.
00001 /**
00002 \file    Plot2D_OptionFile.cpp
00003 \brief   The option file class for Plot2D.
00004 
00005 \author  Glenn D. MacGougan (GDM)
00006 \date    2007-12-19
00007 \since   2007-12-19
00008 
00009 \b "LICENSE INFORMATION" \n
00010 Copyright (c) 2007, refer to 'author' doxygen tags \n
00011 All rights reserved. \n
00012 
00013 Redistribution and use in source and binary forms, with or without
00014 modification, are permitted provided the following conditions are met: \n
00015 
00016 - Redistributions of source code must retain the above copyright
00017   notice, this list of conditions and the following disclaimer. \n
00018 - Redistributions in binary form must reproduce the above copyright
00019   notice, this list of conditions and the following disclaimer in the
00020   documentation and/or other materials provided with the distribution. \n
00021 - The name(s) of the contributor(s) may not be used to endorse or promote 
00022   products derived from this software without specific prior written 
00023   permission. \n
00024 
00025 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00026 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00029 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00031 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00032 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00033 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00034 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00035 SUCH DAMAGE.
00036 */
00037 
00038 #include <memory.h>
00039 #include "Plot2D_OptionFile.h"
00040 #include "StdStringUtils.h"
00041 
00042 namespace namespace_Plot2D
00043 {
00044   Plot2D_OptionFile::~Plot2D_OptionFile()
00045   {
00046   }
00047 
00048 
00049   Plot2D_OptionFile::Plot2D_OptionFile()
00050     : 
00051     m_NumberOfSeries(1),
00052     m_PlotSize_Width(11),
00053     m_PlotSize_Height(9),
00054     m_PlotStatistics(true),
00055     m_PlaceLabelBelowThePlot(false),
00056     m_FigureBackgroundColor(CPLOT_WHITE),
00057     m_UseGPSLabel(false),
00058     m_UTCOffset(false),
00059     m_rightY_scale_factor(1.0),
00060     m_rightY_offset(0)
00061   {
00062     int i;
00063     for( i = 0; i < 12; i++ )
00064     {
00065       m_Series[i].Color = (CPLOT_enumColor)(i+2);
00066       m_Series[i].IsConnected = true;
00067       m_Series[i].MarkOutlierData = true;
00068       m_Series[i].Precision = 6;    
00069       m_Series[i].X_Column = 0;
00070       m_Series[i].Y_Column = i+1;
00071     }    
00072     m_OutputFileName = "plot2d.bmp";
00073   }
00074 
00075   bool Plot2D_OptionFile::ReadAndInterpretOptions( const std::string OptionFilePath )
00076   {
00077     int i;
00078     char buffer[256];
00079     std::string tmpstr;
00080     std::string str;
00081     std::string color_str;
00082     if( !ReadOptionFile( OptionFilePath ) )
00083       return false;
00084 
00085     if( !GetValue( "OutputFileName", m_OutputFileName ) )
00086       return false;
00087 
00088     if( !GetValue( "NumberOfSeries", m_NumberOfSeries ) )
00089       return false;
00090     if( m_NumberOfSeries <= 0 )
00091       return false;
00092 
00093     if( !GetValue( "PlotSize_Width", m_PlotSize_Width ) )
00094       return false;
00095     if( m_PlotSize_Width <= 0 || m_PlotSize_Width > 30 )
00096       return false;
00097 
00098     if( !GetValue( "PlotSize_Height", m_PlotSize_Height ) )
00099       return false;
00100     // do not allow very large image generation
00101     if( m_PlotSize_Height <= 0 || m_PlotSize_Height > 30 )
00102       return false;
00103 
00104     if( m_NumberOfSeries > 12 )
00105       return false;
00106 
00107     GetValue( "Title", m_Title );
00108 
00109     GetValue( "X_IsGridOn", m_xAxis.isGridOn ); 
00110     GetValue( "X_Label", m_xAxis.label );
00111     GetValue( "X_LowerLimit", m_xAxis.lower_limit.str );
00112     GetValue( "X_UpperLimit", m_xAxis.upper_limit.str );
00113     GetValue( "X_TickStart", m_xAxis.tick_start.str );
00114     GetValue( "X_TickSize", m_xAxis.tick_size.str );
00115     GetValue( "X_TickEnd", m_xAxis.tick_end.str );
00116 
00117     DetermineValueOrDefault( m_xAxis.lower_limit );
00118     DetermineValueOrDefault( m_xAxis.upper_limit );
00119     DetermineValueOrDefault( m_xAxis.tick_start );
00120     DetermineValueOrDefault( m_xAxis.tick_size );
00121     DetermineValueOrDefault( m_xAxis.tick_end );
00122 
00123     GetValue( "Y_IsGridOn", m_yAxis.isGridOn ); 
00124     GetValue( "Y_Label", m_yAxis.label );
00125     GetValue( "Y_LowerLimit", m_yAxis.lower_limit.str );
00126     GetValue( "Y_UpperLimit", m_yAxis.upper_limit.str );
00127     GetValue( "Y_TickStart", m_yAxis.tick_start.str );
00128     GetValue( "Y_TickSize", m_yAxis.tick_size.str );
00129     GetValue( "Y_TickEnd", m_yAxis.tick_end.str );
00130 
00131     DetermineValueOrDefault( m_yAxis.lower_limit );
00132     DetermineValueOrDefault( m_yAxis.upper_limit );
00133     DetermineValueOrDefault( m_yAxis.tick_start );
00134     DetermineValueOrDefault( m_yAxis.tick_size );
00135     DetermineValueOrDefault( m_yAxis.tick_end );
00136 
00137     GetValue( "PlotStatistics", m_PlotStatistics );
00138 
00139     GetValue( "PlaceLabelBelowThePlot", m_PlaceLabelBelowThePlot );
00140 
00141     if( GetValue( "FigureBackgroundColor", color_str ) && color_str.length() > 0 )
00142     {
00143       DetermineColorFromString( m_FigureBackgroundColor, color_str );
00144     }
00145 
00146     GetValue( "X_UseGPSLabel", m_UseGPSLabel );
00147 
00148     if( m_UseGPSLabel )
00149     {
00150       m_UTCOffset = 0;
00151       GetValue( "X_GPSUTCOffset", m_UTCOffset );
00152     }
00153 
00154     GetValue( "Y_RightYLabel", m_rightY_label );
00155     if( !m_rightY_label.empty() )
00156     {
00157       GetValue( "Y_RightYScaleFactor", m_rightY_scale_factor );
00158       GetValue( "Y_RightYOffset", m_rightY_offset );
00159     }
00160 
00161 
00162     for( i = 0; i < m_NumberOfSeries; i++ )
00163     {
00164       sprintf( buffer, "Series%d_", i+1 );
00165       str = buffer;
00166 
00167       tmpstr = str;
00168       tmpstr += "DataPath";
00169       if( !GetValue( tmpstr, m_Series[i].DataPath ) )
00170         return false;
00171 
00172       tmpstr = str;
00173       tmpstr += "X_Column";
00174       if( !GetValue( tmpstr, m_Series[i].X_Column ) )
00175         return false;
00176       if( m_Series[i].X_Column == 0 )
00177         return false;
00178       m_Series[i].X_Column--; // make zero based index
00179 
00180       tmpstr = str;
00181       tmpstr += "Y_Column";
00182       if( !GetValue( tmpstr, m_Series[i].Y_Column ) )
00183         return false;
00184       if( m_Series[i].Y_Column == 0 )
00185         return false;
00186       m_Series[i].Y_Column--; // make zero based index
00187 
00188       tmpstr = str;
00189       tmpstr += "IsConnected";
00190       GetValue( tmpstr, m_Series[i].IsConnected );
00191 
00192       tmpstr = str;
00193       tmpstr += "Color";
00194       if( GetValue( tmpstr, color_str ) && color_str.length() > 0 )
00195       {
00196         DetermineColorFromString( m_Series[i].Color, color_str );
00197       }
00198       else
00199       {
00200         if( i == 0 )
00201           m_Series[i].Color = CPLOT_BLUE;
00202         else
00203           m_Series[i].Color = (CPLOT_enumColor)(m_Series[i-1].Color+1);
00204 
00205       }
00206         
00207       tmpstr = str;
00208       tmpstr += "Label";
00209       GetValue( tmpstr, m_Series[i].Label );
00210 
00211       tmpstr = str;
00212       tmpstr += "Units";
00213       GetValue( tmpstr, m_Series[i].Units );
00214 
00215       if( m_PlotStatistics )
00216       {
00217         tmpstr = str;
00218         tmpstr += "Precision";
00219         GetValue( tmpstr, m_Series[i].Precision );
00220       }
00221 
00222       tmpstr = str;
00223       tmpstr += "MarkOutlierData";
00224       GetValue( tmpstr, m_Series[i].MarkOutlierData );
00225 
00226       if( !m_rightY_label.empty() )
00227       {
00228         tmpstr = str;
00229         tmpstr += "UsesRightYLabel";
00230         GetValue( tmpstr, m_Series[i].UsesRightYLabel );
00231       }
00232     }
00233     
00234     return true;
00235   }
00236 
00237   void Plot2D_OptionFile::DetermineValueOrDefault( PLOT2D_structAxisSubOption &s )
00238   {
00239     s.useDefault = true;
00240     if( !s.str.empty() )
00241     {
00242       StdStringUtils::MakeUpper( s.str );
00243 
00244       if( s.str.compare("DEFAULT") != 0 )
00245       {
00246         if( StdStringUtils::GetDouble( s.str, s.val ) )
00247           s.useDefault = false;
00248       }
00249     }
00250   }
00251 
00252   bool Plot2D_OptionFile::DetermineColorFromString( CPLOT_enumColor &color, std::string color_str )
00253   {
00254     StdStringUtils::MakeLower( color_str );
00255     
00256     if( color_str.compare( "white" ) == 0 )
00257       color = CPLOT_WHITE;
00258     else if( color_str.compare( "black" ) == 0 )
00259       color = CPLOT_BLACK;
00260     else if( color_str.compare( "blue" ) == 0 )
00261       color = CPLOT_BLUE;
00262     else if( color_str.compare( "green" ) == 0 )
00263       color = CPLOT_GREEN;
00264     else if( color_str.compare( "purple" ) == 0 )
00265       color = CPLOT_PURPLE;
00266     else if( color_str.compare( "magenta" ) == 0 )
00267       color = CPLOT_MAGENTA;
00268     else if( color_str.compare( "darkblue" ) == 0 )
00269       color = CPLOT_DARKBLUE;
00270     else if( color_str.compare( "indianred" ) == 0 )
00271       color = CPLOT_INDIANRED;
00272     else if( color_str.compare( "babyblue" ) == 0 )
00273       color = CPLOT_BABYBLUE;
00274     else if( color_str.compare( "paislyblue" ) == 0 )
00275       color = CPLOT_PAISLYBLUE;
00276     else if( color_str.compare( "lightpurple" ) == 0 )
00277       color = CPLOT_LIGHTPURPLE;
00278     else if( color_str.compare( "darkpurple" ) == 0 )
00279       color = CPLOT_DARKPURPLE;
00280     else if( color_str.compare( "greypurple" ) == 0 )
00281       color = CPLOT_GREYPURPLE;
00282     else if( color_str.compare( "brown" ) == 0 )
00283       color = CPLOT_BROWN;
00284     else if( color_str.compare( "red" ) == 0 )
00285       color = CPLOT_RED;
00286     else if( color_str.compare( "pink" ) == 0 )
00287       color = CPLOT_PINK;
00288     else if( color_str.compare( "yellow" ) == 0 )
00289       color = CPLOT_YELLOW;
00290     else if( color_str.compare( "orange" ) == 0 )
00291       color = CPLOT_ORANGE;
00292     else if( color_str.compare( "cyan" ) == 0 )
00293       color = CPLOT_CYAN;
00294     else if( color_str.compare( "limegreen" ) == 0 )
00295       color = CPLOT_LIMEGREEN;
00296     else if( color_str.compare( "grey" ) == 0 )
00297       color = CPLOT_GREY;
00298     else if( color_str.compare( "lightgrey" ) == 0 )
00299       color = CPLOT_LIGHTGREY;
00300     else
00301       color = CPLOT_BLACK;
00302 
00303     return true;
00304   }
00305 
00306 } // end of namespace Plot2D;
00307 
00308