appsettings.cpp

Go to the documentation of this file.
00001 // Name:        appsettings.cpp
00002 // Purpose:     
00003 // Author:      NDA
00004 // Modified by: 
00005 // Created:     11/23/05 16:17:15
00006 // RCS-ID:      
00007 // Copyright:   CAEN S.p.A. All rights reserved
00008 // Licence:     
00010 
00011 
00012 #if defined(__GNUG__) && !defined(__APPLE__)
00013 #pragma implementation "appsettings.h"
00014 #endif
00015 
00016 // For compilers that support precompilation, includes "wx/wx.h".
00017 #include "wx/wxprec.h"
00018 
00019 #ifdef __BORLANDC__
00020 #pragma hdrstop
00021 #endif
00022 
00023 #ifndef WX_PRECOMP
00024 #include "wx/wx.h"
00025 #endif
00026 #include <wx/arrimpl.cpp> 
00027 #include <wx/config.h>                  
00028 #include <wx/confbase.h>                
00029 #include <wx/fileconf.h>                
00030 #include <wx/filename.h>
00031 #include <wx/dir.h>
00032 
00033 
00034 #include "appsettings.h"
00035 #include "V1724_board.h"
00036 #include "rpn_handler.h"
00037 
00038 
00039 #ifndef CAEN_VME_INVALID_HANDLE
00040         #define CAEN_VME_INVALID_HANDLE                 -1
00041 #endif
00042 
00043 AppSettings::AppSettings( void (* scope_refresh)( int, bool)): m_vme_link(0), m_vme_board_num(0), m_vme_handle( CAEN_VME_INVALID_HANDLE),
00044                                                                 ScopeRefresh( scope_refresh), m_mutex( wxMUTEX_RECURSIVE)
00045 {
00046 
00047         wxString setting_filename= wxGetCwd()+ wxFileName::GetPathSeparator()+ _("settings.txt");
00048         if( wxTheApp->argc>= 2)
00049                 setting_filename= wxGetCwd()+ wxFileName::GetPathSeparator()+ wxTheApp->argv[ 1];
00050 
00051         wxConfigBase::Set( new wxFileConfig( wxEmptyString, wxEmptyString, setting_filename, setting_filename, wxCONFIG_USE_LOCAL_FILE ));
00052 
00053         for( int i= 0; i< SCOPE_NUM_PANELS; i++)
00054         {
00055                 m_grid_pen[ i]= NULL;
00056                 m_mid_grid_pen[ i]= NULL;
00057                 m_back_brush[ i]= NULL;
00058         }
00059 }
00060 
00061 AppSettings::~AppSettings(void)
00062 {
00063         delete wxConfigBase::Set((wxConfigBase *) NULL);
00064 
00065         // Delete channel list
00066         for( size_t i= 0; i< this->m_board_array.GetCount(); i++)
00067         {
00068                 delete (GenericBoard*)this->m_board_array[i];
00069         }
00070         this->m_board_array.Clear();
00071 
00072         // Close VME handling
00073         this->EndVME();
00074 
00075         for( int i= 0; i< SCOPE_NUM_PANELS; i++)
00076         {
00077                 if( this->m_grid_pen[ i]!= NULL)
00078                 {
00079                         delete this->m_grid_pen[ i];
00080                         this->m_grid_pen[ i]= NULL;
00081                 }
00082                 if( this->m_mid_grid_pen[ i]!= NULL)
00083                 {
00084                         delete this->m_mid_grid_pen[ i];
00085                         this->m_mid_grid_pen[ i]= NULL;
00086                 }
00087                 if( this->m_back_brush[ i]!= NULL)
00088                 {       
00089                         delete this->m_back_brush[ i];
00090                         this->m_back_brush[ i]= NULL;
00091                 }
00092         }
00093 }
00097 bool AppSettings::Load( void)
00098 {
00099         /*
00100         Application setting file structure
00101         [RECORD]
00102         |
00103         |- RECORD_FOLDER= ./record/           // The folder where to store record files
00104         [TRIGGER]
00105         |
00106         |- TRIGGER_MSK= 0                     // Bitmask : 0x0001: external 0x0002: Channels 0x0004: autoretrig 
00107         |- POST_TRIGGER= 0       
00108         |- TRIGGER_POSITION_KEEP= 0       
00109         |- SAMPLE_BLOCK_SIZE= 0                    
00110     |- TRIGGER_EDGE= 0               // 0: No Trigger  1: Rising edge  2: Falling edge
00111         [MISC]
00112         |
00113         |- VME_BOARD_TYPE=V1718
00114         |- VME_LINK=0
00115         |- VME_BOARD_NUM=0
00116         |- STARTED=0                                                                    // Get acquisition status upon loading
00117         |- SHOW_LEFT_PANE= 0                                                    // Get the left pane show status upon loading
00118         |- SHOW_BOTTOM_PANE= 0                                                  // Get the bottom pane show status upon loading
00119         |- SHOW_SCOPE_0_PANE= 0                                                 // Get the scope 0 pane show status upon loading
00120         |- SHOW_SCOPE_1_PANE= 0                                                 // Get the scope 1 pane show status upon loading
00121         |- SHOW_SCOPE_2_PANE= 0                                                 // Get the scope 2 pane show status upon loading
00122         |- SHOW_SCOPE_3_PANE= 0                                                 // Get the scope 3 pane show status upon loading
00123         |- GRID_LINE_COLOR_0= 0xffffff                                  // RGB grid color for scope 0
00124         |- GRID_LINE_COLOR_1= 0xffffff                                  // RGB grid color for scope 1
00125         |- GRID_LINE_COLOR_2= 0xffffff                                  // RGB grid color for scope 2
00126         |- GRID_LINE_COLOR_3= 0xffffff                                  // RGB grid color for scope 3
00127         |- GRID_LINE_TYPE_0= 0                                                  // Grid line type for scope 0
00128         |- GRID_LINE_TYPE_1= 0                                                  // Grid line type for scope 1
00129         |- GRID_LINE_TYPE_2= 0                                                  // Grid line type for scope 2
00130         |- GRID_LINE_TYPE_3= 0                                                  // Grid line type for scope 3
00131         |- GRID_LINE_WIDTH_0= 1                                                 // Grid line width for scope 0
00132         |- GRID_LINE_WIDTH_1= 1                                                 // Grid line width for scope 1
00133         |- GRID_LINE_WIDTH_2= 1                                                 // Grid line width for scope 2
00134         |- GRID_LINE_WIDTH_3= 1                                                 // Grid line width for scope 3
00135         |- OFFSET_SEC_0= 0.0                                                    // Horizontal offset for scope 0
00136         |- OFFSET_SEC_1= 0.0                                                    // Horizontal offset for scope 1
00137         |- OFFSET_SEC_2= 0.0                                                    // Horizontal offset for scope 2
00138         |- OFFSET_SEC_3= 0.0                                                    // Horizontal offset for scope 3
00139         |- SEC_2_DIV_0= 1000                                                    // Div/ Sec conversion factor ( div_val= SEC_2_DIV* sec_val) for scope 0
00140         |- SEC_2_DIV_1= 1000                                                    // Div/ Sec conversion factor ( div_val= SEC_2_DIV* sec_val) for scope 1
00141         |- SEC_2_DIV_2= 1000                                                    // Div/ Sec conversion factor ( div_val= SEC_2_DIV* sec_val) for scope 2
00142         |- SEC_2_DIV_3= 1000                                                    // Div/ Sec conversion factor ( div_val= SEC_2_DIV* sec_val) for scope 3
00143         |- BACKGROUND_COLOR_0= 0x000000                                 // RGB color background color for scope 0
00144         |- BACKGROUND_COLOR_1= 0x000000                                 // RGB color background color for scope 1
00145         |- BACKGROUND_COLOR_2= 0x000000                                 // RGB color background color for scope 2
00146         |- BACKGROUND_COLOR_3= 0x000000                                 // RGB color background color for scope 3
00147         |- EXT_RATE_MHZ= 100000000                                              // external sample rate (MHz)
00148         |- INT_RATE_MHZ= 100000000                                              // internal sample rate (MHz)
00149         |- USE_EXT_CLOCK= 0                                                             // use external clock
00150         |- USE_TTL= 0                                                                   // use TTL/NIM external signals
00151         |- MAX_LOG_X= 1000
00152         |- ACQ_BOARD_NUM= N
00153         [ACQ_BOARDS]
00154         |
00155         |- [0]
00156         |   |
00157         |   |- BOARD_TYPE= V1724
00158         |   |- { OTHER BOARD DATA}
00159         |   ...
00160         |- [N- 1]
00161         |   |
00162         |   |- BOARD_TYPE= V1724
00163         |   |- { OTHER BOARD DATA}
00164         */
00165         unsigned int i;
00166         // Delete previously stored boards
00167         this->m_board_array.Clear();
00168         wxConfigBase* config= wxConfigBase::Get( false);
00169         if( !config)
00170         {
00171                 wxLogError( _("Cannot get configuration file\n"));
00172                 return false;
00173         }
00174 
00175         wxMutexLocker lock( this->m_mutex);
00176         
00177         //
00178         // Get Record Folder
00179         config->Read(  _("/RECORD/RECORD_FOLDER"), &this->m_record_folder, "./");
00180         // Sanity checks
00181         if( !wxDir::Exists( this->m_record_folder))
00182         {
00183                 // Set to current directory
00184                 this->m_record_folder= "./";
00185         }
00186 
00187         //
00188         // Get Trigger msk
00189         int trigger_msk= 0;
00190         config->Read( _("/TRIGGER/TRIGGER_MSK"), &trigger_msk, 0);
00191         this->m_trigger_msk= (AppSettings::TRIGGER_MSK)trigger_msk;
00192 
00193         //
00194         // Get Post Trigger
00195         this->m_post_trigger= 0;
00196         config->Read( _("/TRIGGER/POST_TRIGGER"), &this->m_post_trigger, 0);
00197 
00198         //
00199         // Get Keep trigger position flags
00200         int tmp;
00201         config->Read( _("/TRIGGER/TRIGGER_POSITION_KEEP"), &tmp, 0);
00202         this->m_trigger_position_keep= tmp? true: false;
00203 
00204 
00205         //
00206         // Get trigger edge type
00207         int edge_type;
00208         config->Read( _("/TRIGGER/TRIGGER_EDGE"), &edge_type, (int)NO_TRIGGER);
00209         this->m_trigger_edge_type= (TRIGGER_EDGE_TYPE)edge_type;
00210 
00211         //
00212         // Get Sample block size
00213         this->m_sample_block_size= 0;
00214         config->Read( _("/TRIGGER/SAMPLE_BLOCK_SIZE"), &this->m_sample_block_size, 0);
00215 
00216         //
00217         // Get VME board type
00218         config->Read( _("/MISC/VME_BOARD_TYPE"), &this->m_vme_board_type_string, _("V1718"));
00219         //
00220         // Get VME board link
00221         config->Read( _("/MISC/VME_LINK"), &this->m_vme_link, 0);
00222         //
00223         // Get VME board number
00224         config->Read( _("/MISC/VME_BOARD_NUM"), &this->m_vme_board_num, 0);
00225 
00226         //
00227         // Get acquisition status upon loading
00228         config->Read( _("/MISC/STARTED"), &tmp, 0);
00229         this->m_started= tmp? true: false;
00230 
00231         //
00232         // Get show left pane status upon loading
00233         config->Read( _("/MISC/SHOW_LEFT_PANE"), &tmp, 0);
00234         this->m_show_left_pane= tmp? true: false;
00235 
00236         //
00237         // Get show bottom pane status upon loading
00238         config->Read( _("/MISC/SHOW_BOTTOM_PANE"), &tmp, 0);
00239         this->m_show_bottom_pane= tmp? true: false;
00240 
00241         //
00242         // Get Show scope left top pane upon loading
00243         config->Read( _("/MISC/SHOW_SCOPE_0_PANE"), &tmp, 0);
00244         this->m_show_scope_left_top_pane= tmp? true: false;
00245 
00246         //
00247         // Get Show scope right top pane upon loading
00248         config->Read( _("/MISC/SHOW_SCOPE_1_PANE"), &tmp, 0);
00249         this->m_show_scope_right_top_pane= tmp? true: false;
00250 
00251         //
00252         // Get Show scope left bottom pane upon loading
00253         config->Read( _("/MISC/SHOW_SCOPE_2_PANE"), &tmp, 0);
00254         this->m_show_scope_left_bottom_pane= tmp? true: false;
00255 
00256         //
00257         // Get Show scope right bottom pane upon loading
00258         config->Read( _("/MISC/SHOW_SCOPE_3_PANE"), &tmp, 0);
00259         this->m_show_scope_right_bottom_pane= tmp? true: false;
00260 
00261         for( int scope_index= 0; scope_index< SCOPE_NUM_PANELS; scope_index++)
00262         {
00263                 wxString scope_index_string= wxString::Format( "_%d", scope_index);
00264                 //
00265                 // Get grid line color
00266                 wxString grid_line_color_rgb_string= _("");
00267                 config->Read( _("/MISC/GRID_LINE_COLOR")+ scope_index_string, &grid_line_color_rgb_string, _("0xffffff"));
00268                 unsigned long grid_line_color_rgb;
00269                 wxString hex_part;
00270                 if( grid_line_color_rgb_string.Upper().StartsWith(_("0X"), &hex_part))
00271                 {
00272                         // Hex format
00273                         if( !hex_part.Trim().ToULong( &grid_line_color_rgb, 16))
00274                         {
00275                                 grid_line_color_rgb= 0x00ffffff;
00276                         }
00277                 }
00278                 else
00279                 {
00280                         // Decimal format
00281                         if( !grid_line_color_rgb_string.Trim().ToULong( &grid_line_color_rgb, 10))
00282                         {
00283                                 grid_line_color_rgb= 0x00ffffff;
00284                         }
00285                 }
00286                 this->m_grid_line_color[ scope_index].Set( (grid_line_color_rgb>> 16)& 0xff, (grid_line_color_rgb>> 8)& 0xff, grid_line_color_rgb& 0xff);
00287 
00288                 //
00289                 // Get line type
00290                 int grid_line_type;
00291                 config->Read( _("/MISC/GRID_LINE_TYPE")+ scope_index_string, &grid_line_type, 1);
00292                 this->m_grid_line_type[ scope_index]= (GRID_LINE_TYPE)grid_line_type;
00293 
00294                 //
00295                 // Get line width
00296                 config->Read( _("/MISC/GRID_LINE_WIDTH")+ scope_index_string, &this->m_grid_line_width[ scope_index], 1);
00297 
00298                 //
00299                 // Get horizontal offset (sec)
00300                 config->Read( _("/MISC/OFFSET_SEC")+ scope_index_string, &this->m_offset_sec[ scope_index], 0.0);
00301 
00302                 //
00303                 // Get Div/ Sec conversion factor
00304                 config->Read( _("/MISC/SEC_2_DIV")+ scope_index_string, &this->m_sec_2_div[ scope_index], 1000.0);
00305                 this->SetSec2Div( scope_index, this->m_sec_2_div[ scope_index]);
00306 
00307                 //
00308                 // Get background color
00309                 wxString back_color_rgb_string= _("");
00310                 config->Read( _("/MISC/BACKGROUND_COLOR")+ scope_index_string, &back_color_rgb_string, _("0x000000"));
00311                 unsigned long back_color_rgb;
00312                 if( back_color_rgb_string.Upper().StartsWith(_("0X"), &hex_part))
00313                 {
00314                         // Hex format
00315                         if( !hex_part.Trim().ToULong( &back_color_rgb, 16))
00316                         {
00317                                 back_color_rgb= 0x00ffffff;
00318                         }
00319                 }
00320                 else
00321                 {
00322                         // Decimal format
00323                         if( !back_color_rgb_string.Trim().ToULong( &back_color_rgb, 10))
00324                         {
00325                                 back_color_rgb= 0x00ffffff;
00326                         }
00327                 }
00328                 this->m_background_color[ scope_index].Set( (back_color_rgb>> 16)& 0xff, (back_color_rgb>> 8)& 0xff, back_color_rgb& 0xff);
00329         }
00330         //
00331         // Get internal sample rate (MHz)
00332         config->Read( _("/MISC/INT_RATE_MHZ"), &this->m_int_rate_MHz, 100000000);
00333         //
00334         // Get external sample rate (MHz)
00335         config->Read( _("/MISC/EXT_RATE_MHZ"), &this->m_ext_rate_MHz, 100000000);
00336         //
00337         // Get clock type usage (internal or external)
00338         config->Read( _("/MISC/USE_EXT_CLOCK"), &tmp, 0);
00339         this->m_use_ext_clock= tmp? true: false;
00340         
00341         this->SetClock( this->m_use_ext_clock, this->m_ext_rate_MHz);
00342 
00343         //
00344         // Get clock type usage (internal or external)
00345         config->Read( _("/MISC/USE_TTL"), &tmp, 0);
00346         this->m_use_TTL= tmp? true: false;
00347 
00348         //
00349         // Get maximum logical value X
00350         config->Read( _("/MISC/MAX_LOG_X"), &this->m_max_log_X, 1024);
00351 
00352 
00353         int acq_board_num= 0;
00354         config->Read( _("/MISC/ACQ_BOARD_NUM"), &acq_board_num, 0);
00355 
00356         this->InitVME();
00357         wxString board_base_string= _("/ACQ_BOARDS/");
00358         //
00359         // Boards loop
00360         for( i= 0; i< (unsigned int)acq_board_num; i++)
00361         {
00362                 wxString board_string= wxString::Format( "%s%i/", board_base_string.c_str(), i);
00363                 //
00364                 // Get the board type
00365                 wxString board_type= _("");
00366                 config->Read( board_string+ _("BOARD_TYPE"), &board_type, _("V1724"));
00367                 if( !board_type.Trim().CmpNoCase( _("V1724")))
00368                 {
00369                         // V1724
00370                         this->m_board_array.Add( new V1724Board( i, this->ScopeRefresh, &this->m_mutex, this));
00371                 }
00372                 else
00373                 {
00374                         // Unknown board type
00375                         wxLogError( wxString::Format( "Unknown board type '%s'\n", board_type.c_str()));
00376                         // return false;
00377                 }
00378 
00379                 // Open board handlers
00380                 if( !((GenericBoard*)this->m_board_array[i])->Open( this->m_vme_handle ))
00381                 {
00382                         wxLogError( _("Board open failure\n"));
00383                         //return false;
00384                 }
00385                 // Load board section
00386                 if( !((GenericBoard*)this->m_board_array[i])->LoadConfig( config, board_string))
00387                 {
00388                         wxLogError( _("Error loading board settings\n"));
00389                         //return false;
00390                 }
00391                 // Init board section
00392                 if( !((GenericBoard*)this->m_board_array[i])->Init( this->m_vme_handle))
00393                 {
00394                         wxLogError( _("Board init failure\n"));
00395                         //return false;
00396                 }
00397         }
00398 
00399         return true;
00400 }
00401 
00405 bool AppSettings::Save( void)
00406 {
00407         wxConfigBase* config= wxConfigBase::Get( false);
00408         if( !config)
00409                 return false;
00410         wxMutexLocker lock( this->m_mutex);
00411 
00412         //
00413         // Delete groups
00414         wxString group_id;
00415         long group_index;
00416         while( config->GetFirstGroup( group_id, group_index))
00417         {
00418                 config->DeleteGroup( group_id);
00419         }
00420         //
00421         // Set Record Folder
00422         if( !config->Write( _("/RECORD/RECORD_FOLDER"), this->m_record_folder))
00423                 return false;
00424 
00425         //
00426         // Set Trigger msk
00427         if( !config->Write( _("/TRIGGER/TRIGGER_MSK"), (int)this->m_trigger_msk))
00428                 return false;
00429 
00430         //
00431         // Set Post Trigger
00432         if( !config->Write( _("/TRIGGER/POST_TRIGGER"), this->m_post_trigger))
00433                 return false;
00434 
00435         //
00436         // Set Keep trigger position flags
00437         config->Write( _("/TRIGGER/TRIGGER_POSITION_KEEP"), this->m_trigger_position_keep? 1: 0);
00438 
00439         //
00440         // Set trigger edge type
00441         if( !config->Write( _("/TRIGGER/TRIGGER_EDGE"), (int)this->m_trigger_edge_type))
00442                 return false;
00443 
00444         //
00445         // Set Sample buffer size
00446         if( !config->Write( _("/TRIGGER/SAMPLE_BLOCK_SIZE"), this->m_sample_block_size))
00447                 return false;
00448 
00449         //
00450         // Set VME board type
00451         if( !config->Write( _("/MISC/VME_BOARD_TYPE"), this->m_vme_board_type_string))
00452                 return false;
00453         //
00454         // Set VME board link
00455         if( !config->Write( _("/MISC/VME_LINK"), this->m_vme_link))
00456                 return false;
00457         //
00458         // Set VME board number
00459         if( !config->Write( _("/MISC/VME_BOARD_NUM"), this->m_vme_board_num))
00460                 return false;
00461 
00462         //
00463         // Set acquisition status upon loading
00464         config->Write( _("/MISC/STARTED"), this->m_started? 1: 0);
00465 
00466         //
00467         // Set show left pane status upon loading
00468         config->Write( _("/MISC/SHOW_LEFT_PANE"), this->m_show_left_pane? 1: 0);
00469 
00470         //
00471         // Set show bottom pane status upon loading
00472         config->Write( _("/MISC/SHOW_BOTTOM_PANE"), this->m_show_bottom_pane? 1: 0);
00473 
00474         //
00475         // Get Show scope left top pane upon loading
00476         config->Write( _("/MISC/SHOW_SCOPE_0_PANE"), m_show_scope_left_top_pane? 1: 0);
00477 
00478         //
00479         // Get Show scope right top pane upon loading
00480         config->Write( _("/MISC/SHOW_SCOPE_1_PANE"), m_show_scope_right_top_pane? 1: 0);
00481 
00482         //
00483         // Get Show scope left bottom pane upon loading
00484         config->Write( _("/MISC/SHOW_SCOPE_2_PANE"), m_show_scope_left_bottom_pane? 1: 0);
00485 
00486         //
00487         // Get Show scope right bottom pane upon loading
00488         config->Write( _("/MISC/SHOW_SCOPE_3_PANE"), m_show_scope_right_bottom_pane? 1: 0);
00489 
00490         for( int scope_index= 0; scope_index< SCOPE_NUM_PANELS; scope_index++)
00491         {
00492                 wxString scope_index_string= wxString::Format( "_%d", scope_index);
00493 
00494                 //
00495                 // Set grid line color
00496                 wxString grid_line_color_rgb_string= wxString::Format( "0x%02x%02x%02x", this->m_grid_line_color[ scope_index].Red(), this->m_grid_line_color[ scope_index].Green(), this->m_grid_line_color[ scope_index].Blue());
00497                 if( !config->Write( _("/MISC/GRID_LINE_COLOR")+ scope_index_string, grid_line_color_rgb_string))
00498                         return false;
00499 
00500                 //
00501                 // Set line type
00502                 if( !config->Write( _("/MISC/GRID_LINE_TYPE")+ scope_index_string, (int)this->m_grid_line_type[ scope_index]))
00503                         return false;
00504 
00505                 //
00506                 // Set line width
00507                 if( !config->Write( _("/MISC/GRID_LINE_WIDTH")+ scope_index_string, this->m_grid_line_width[ scope_index]))
00508                         return false;
00509 
00510                 //
00511                 // Set horizontal offset (sec)
00512                 if( !config->Write( _("/MISC/OFFSET_SEC")+ scope_index_string, this->m_offset_sec[ scope_index]))
00513                         return false;
00514         
00515                 //
00516                 // Set Div/ Sec conversion factor
00517                 if( !config->Write( _("/MISC/SEC_2_DIV")+ scope_index_string, this->m_sec_2_div[ scope_index]))
00518                         return false;
00519 
00520                 //
00521                 // Set grid line color
00522                 wxString back_color_rgb_string= wxString::Format( "0x%02x%02x%02x", this->m_background_color[ scope_index].Red(), this->m_background_color[ scope_index].Green(), this->m_background_color[ scope_index].Blue());
00523                 if( !config->Write( _("/MISC/BACKGROUND_COLOR")+ scope_index_string, back_color_rgb_string))
00524                         return false;
00525         }
00526         //
00527         // Set internal sample rate (MHz)
00528         if( !config->Write( _("/MISC/INT_RATE_MHZ"), this->m_int_rate_MHz))
00529                 return false;
00530 
00531         //
00532         // Set external sample rate (MHz)
00533         if( !config->Write( _("/MISC/EXT_RATE_MHZ"), this->m_ext_rate_MHz))
00534                 return false;
00535         //
00536         // Set clock type usage (internal or external)
00537         if( !config->Write( _("/MISC/USE_EXT_CLOCK"), this->m_use_ext_clock? 1: 0))
00538                 return false;
00539 
00540         //
00541         // Set external signals standard: TTL/NIM
00542         if( !config->Write( _("/MISC/USE_TTL"), this->m_use_TTL? 1: 0))
00543                 return false;
00544 
00545         //
00546         // Set maximum logical value X
00547         if( !config->Write( _("/MISC/MAX_LOG_X"), this->m_max_log_X))
00548                 return false;
00549 
00550         //
00551         // Set board number
00552         if( !config->Write( _("/MISC/ACQ_BOARD_NUM"), (int)this->m_board_array.GetCount()))
00553                 return false;
00554 
00555         wxString board_base_string= _("/ACQ_BOARDS/");
00556         //
00557         // Boards loop
00558         for( size_t i= 0; i< this->m_board_array.GetCount(); i++)
00559         {
00560                 wxString board_string= wxString::Format( "%s%i/", board_base_string.c_str(), i);
00561                 //
00562                 // Set the board type
00563                 if( !config->Write( board_string+ _("BOARD_TYPE"), ((GenericBoard*)this->m_board_array[i])->GetType()))
00564                         return false;
00565 
00566                 // Save board section
00567                 if( !((GenericBoard*)this->m_board_array[i])->SaveConfig( config, board_string))
00568                         return false;
00569         }
00570 
00571         if( !config->Flush())
00572                 return false;
00573         return true;
00574 }
00575 bool AppSettings::InitVME( void)
00576 {
00577         // Init CAEN VME handle
00578         CVBoardTypes vme_board_type;
00579         if( !this->m_vme_board_type_string.CmpNoCase(_("V1718")))
00580         {
00581                 vme_board_type= cvV1718;
00582         }
00583         else if( !this->m_vme_board_type_string.CmpNoCase(_("V2718")))
00584         {
00585                 vme_board_type= cvV2718;
00586         }
00587         else
00588         {
00589                 wxLogError( wxString::Format( _("Unhandled board type: %s"), this->m_vme_board_type_string.c_str()));
00590                 return false;
00591         }
00592         CVErrorCodes cv_error_code;
00593         if( ( cv_error_code= CAENVME_Init( vme_board_type, this->m_vme_link, this->m_vme_board_num, &this->m_vme_handle))!= cvSuccess)
00594         {
00595                 wxLogError( wxString::Format( _("VME Init failure board type= %s link= %i board num= %i error= %s"), this->m_vme_board_type_string.c_str(), this->m_vme_link, this->m_vme_board_num, CAENVME_DecodeError( cv_error_code) ));
00596                 return false;
00597         }
00598         return true;
00599 }
00600 bool AppSettings::EndVME( void)
00601 {
00602         CVErrorCodes cv_error_code;
00603         if( ( cv_error_code= CAENVME_End( this->m_vme_handle))!= cvSuccess)
00604         {
00605                 wxLogError( wxString::Format( _("VME End failure board type= %s link= %i board num= %i error= %s\n"), this->m_vme_board_type_string.c_str(), this->m_vme_link, this->m_vme_board_num, CAENVME_DecodeError( cv_error_code)));
00606                 return false;
00607         }               
00608         this->m_vme_handle= CAEN_VME_INVALID_HANDLE;
00609         return true;
00610 }
00611 
00612 bool AppSettings::SetGridPen( int scope_index, const wxPen* grid_pen, const wxPen* mid_grid_pen)
00613 {
00614         if( this->m_grid_pen[ scope_index]!= NULL)
00615         {
00616                 delete this->m_grid_pen[ scope_index];
00617                 this->m_grid_pen[ scope_index]= NULL;
00618         }
00619         this->m_grid_pen[ scope_index]= ( grid_pen== NULL)? NULL: new wxPen( *grid_pen);
00620 
00621         if( this->m_mid_grid_pen[ scope_index]!= NULL)
00622         {
00623                 delete this->m_mid_grid_pen[ scope_index];
00624                 this->m_mid_grid_pen[ scope_index]= NULL;
00625         }
00626         if( mid_grid_pen== NULL)
00627         {
00628                 this->m_mid_grid_pen[ scope_index]= ( grid_pen== NULL)? NULL: new wxPen( *grid_pen);
00629         }
00630         else
00631         {
00632                 this->m_mid_grid_pen[ scope_index]= new wxPen( *mid_grid_pen);
00633         }
00634         return true;
00635 }
00636 
00637 bool AppSettings::SetBackBrush( int scope_index, const wxBrush* back_brush)
00638 {
00639         if( this->m_back_brush[ scope_index]!= NULL)
00640         {       
00641                 delete this->m_back_brush[ scope_index];
00642                 this->m_back_brush[ scope_index]= NULL;
00643         }
00644         this->m_back_brush[ scope_index]= ( back_brush== NULL)? NULL: new wxBrush( *back_brush);
00645         return true;
00646 }
00647 
00648 void AppSettings::SetDiv2Pix( int scope_index, double div_2_pix_X)
00649 {
00650         wxMutexLocker lock( this->m_mutex);
00651 
00652         this->m_div_2_pix_X[ scope_index]= div_2_pix_X;
00653         this->m_sec_2_pix[ scope_index]= this->m_sec_2_div[ scope_index]* this->m_div_2_pix_X[ scope_index];
00654 }
00655 
00656 void AppSettings::SetSec2Div( int scope_index, double sec_2_div)
00657 {
00658         if( sec_2_div< 0.0000001)
00659                 sec_2_div= 0.0000001;
00660         this->m_sec_2_div[ scope_index]= sec_2_div;
00661 
00662         this->m_sec_2_pix[ scope_index]= this->m_sec_2_div[ scope_index]* this->m_div_2_pix_X[ scope_index];
00663 }
00664 
00665 void AppSettings::SetSec2Sample( double sec_2_sample)
00666 {
00667         if( sec_2_sample< 0.0000000001)
00668                 sec_2_sample= 0.0000000001;
00669         this->m_sec_2_sample= sec_2_sample;
00670 
00671         this->m_sample_2_sec= 1/ this->m_sec_2_sample;
00672 }
00673 void AppSettings::SetClock( bool use_ext_clock, int ext_rate_MHz)
00674 {
00675         if( ext_rate_MHz< 1)
00676                 ext_rate_MHz= 1;
00677         else if( ext_rate_MHz> 100)
00678                 ext_rate_MHz= 100;
00679         this->m_ext_rate_MHz= ext_rate_MHz;
00680 
00681         this->m_use_ext_clock= use_ext_clock;
00682 
00683         this->SetSec2Sample( this->m_use_ext_clock? (( double) ext_rate_MHz)* 1000000.0: ((double)this->m_int_rate_MHz)* 1000000.0);
00684 }

Generated on Mon Mar 19 17:14:07 2007 for CAENScope by  doxygen 1.4.6-NO