00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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--;
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--;
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 }
00307
00308