Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
ActiveObjectsManager.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "ActiveObjectsManager.h"
14 
15 #include "SampleSet.h"
16 #include "Sample.h"
17 #include "Spectrum.h"
18 #include "Chromatogram.h"
19 #include "DataGroupNode.h"
20 #include "DataMapInfo.h"
21 
22 
23 using namespace kome::objects;
24 
25 
26 #include <crtdbg.h>
27 #ifdef _DEBUG
28  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
29  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
30 #endif // _DEBUG
31 
32 
33 
34 #define HISTORY_COUNT 9
35 #define MRU_SECTION "MRU"
36 
37 
38 // constructor
40 }
41 
42 // destructor
44  // delete filtered spectra
45  for( std::map< Sample*, DataSet* >::iterator it = m_filteredDataSetMap.begin();
46  it != m_filteredDataSetMap.end(); it++ ) {
47  delete (*it).second;
48  }
49  m_filteredDataSetMap.clear();
50  m_acSample = NULL;
51  m_openSpectra.clear();
52 }
53 
54 // get the number of opened samples
56  return m_samples.size();
57 }
58 
59 // get opened sample
60 Sample* ActiveObjectsManager::getOpenedSample( const unsigned int idx ) {
61  if( idx >= m_samples.size() ) {
62  return NULL;
63  }
64  return m_samples[ idx ];
65 }
66 
67 // sets the active sample
69  m_acSample = sample;
70 }
71 
72 // gets the active sample
74  return m_acSample;
75 }
76 
77 // get filtered spectra
79  // get spectra
80  kome::objects::DataSet* dataSet = NULL;
81 
82  if( m_filteredDataSetMap.find( sample ) == m_filteredDataSetMap.end() ) { // new data set
83  dataSet = new DataSet( sample->getRootDataGroupNode() );
84  if( sample != NULL ) {
85  DataGroupNode* root = sample->getRootDataGroupNode();
86  root->getDataSet( dataSet );
87  }
88 
89  for( int i = (int)dataSet->getNumberOfChromatograms() - 1; i >= 0; i-- ) {
90  kome::objects::Chromatogram* chrom = dataSet->getChromatogram( i );
91  if( chrom->isAutoCreated() ) {
92  dataSet->removeChromatogram( chrom );
93  }
94  }
95 
96  m_filteredDataSetMap[ sample ] = dataSet;
97  }
98  else {
99  dataSet = m_filteredDataSetMap[ sample ];
100  }
101 
102  return dataSet;
103 }
104 
105 // search sample
107  for( int i = 0; i < (int)m_samples.size(); i++ ) {
108  if( sample == m_samples[ i ] ) {
109  return i;
110  }
111  }
112  return -1;
113 }
114 
115 // clear history
117  // ini
119  kome::core::IniFile* ini = msppMgr.getIniFile();
120 
121  // clear
122  m_fileHistory.clear();
123 
124  // delete from ini
125  if( ini != NULL ) {
126  for( unsigned int i = 0; i < HISTORY_COUNT; i++ ) {
127  std::string name = FMT( "File%d", ( i + 1 ) );
128  ini->deleteValue( MRU_SECTION, name.c_str() );
129  }
130  }
131 }
132 
133 // add history file
134 void ActiveObjectsManager::addHistoryFile( const char* path ) {
135  // ini
137  kome::core::IniFile* ini = msppMgr.getIniFile();
138 
139  // get history
140  if( m_fileHistory.size() == 0 ) {
142  }
143 
144  // absolutepath
145  std::string p = absolutepath( path );
146 
147  // search
148  int idx = -1;
149  for( unsigned int i = 0; i < m_fileHistory.size() && idx < 0; i++ ) {
150  if( m_fileHistory[ i ].compare( p ) == 0 ) {
151  idx = (int)i;
152  }
153  }
154 
155  if( idx >= 0 ) {
156  m_fileHistory.erase( m_fileHistory.begin() + idx );
157  }
158 
159  // add
160  m_fileHistory.insert( m_fileHistory.begin(), p );
161 
162  // remove
163  while( m_fileHistory.size() > HISTORY_COUNT ) {
164  m_fileHistory.erase( m_fileHistory.begin() + (int)( m_fileHistory.size() - 1 ) );
165  }
166 
167  // ini
168  if( ini != NULL ) {
169  for( unsigned int i = 0; i < m_fileHistory.size(); i++ ) {
170  std::string name = FMT( "File%d", ( i + 1 ) );
171  ini->setString( MRU_SECTION, name.c_str(), m_fileHistory[ i ].c_str() );
172  }
173  }
174 }
175 
176 // remove history file
177 void ActiveObjectsManager::removeHistoryFile( const char* path ) {
178  // absolute path
179  std::string p = absolutepath( path );
180 
181  // copy the array
182  std::vector< std::string > history;
183  if( m_fileHistory.size() > 0 ) {
184  history.resize( m_fileHistory.size() );
185 
186  for( unsigned int i = 0; i < m_fileHistory.size(); i++ ) {
187  history[ i ] = m_fileHistory[ i ];
188  }
189  }
190 
191  // clear
193 
194  // add
195  for( unsigned int i = 0; i < history.size(); i++ ) {
196  if( history[ i ].compare( p ) != 0 ) {
197  addHistoryFile( history[ i ].c_str() );
198  }
199  }
200 }
201 
202 // get the number of history files
204  // get history
205  if( m_fileHistory.size() == 0 ) {
207  }
208 
209  // size
210  return m_fileHistory.size();
211 }
212 
213 // get history file
214 const char* ActiveObjectsManager::getHistoryFile( const unsigned int idx ) {
215  // get history
216  if( m_fileHistory.size() == 0 ) {
218  }
219 
220  // path
221  if( idx >= m_fileHistory.size() ) {
222  return NULL;
223  }
224  return m_fileHistory[ idx ].c_str();
225 }
226 
227 // read history from ini
229  // initialize
230  m_fileHistory.clear();
231 
232  // ini
234  kome::core::IniFile* ini = msppMgr.getIniFile();
235  if( ini == NULL ) {
236  return;
237  }
238 
239  // set
240  bool loop = true;
241  for( unsigned int i = 0; i < HISTORY_COUNT && loop; i++ ) {
242  std::string name = FMT( "File%d", ( i + 1 ) );
243  std::string path = ini->getString( MRU_SECTION, name.c_str(), "" );
244 
245  if( path.empty() ) {
246  loop = false;
247  }
248  else {
249  m_fileHistory.push_back( path );
250  }
251  }
252 }
253 
254 // This method is called when a sample is opened
256  // check
257  if( sample == NULL ) {
258  return;
259  }
260  int idx = searchSample( sample );
261  if( idx >= 0 ) {
262  return;
263  }
264 
265  m_samples.push_back( sample );
266 }
267 
268 // This method is called when a sample is closed
269 void ActiveObjectsManager::onCloseSample( Sample* sample, const bool deleting ) {
270  // delete filtered spectra
271  std::vector< DataGroupNode* > groups;
272  // @date 2012.04.23 <Mod> M.Izumi
273  for( std::map< Sample*, DataSet* >::iterator it = m_filteredDataSetMap.begin();
274  it != m_filteredDataSetMap.end(); it++ ) {
275  // @date 2012.04.23 <Mod> M.Izumi
276  if( sample != NULL && sample == (*it).first ){
277  delete (*it).second;
278 
279  groups.push_back( sample->getRootDataGroupNode() ); // @date 2012.04.23 <Mod> M.Izumi
280  }
281  }
282  for( int i = 0; i < (int)groups.size(); i++ ) {
283  m_filteredDataSetMap.erase( groups[ i ]->getSample() ); // @date 2012.04.23 <Mod> M.Izumi
284  }
285 
286  // delete sample from array
287  int idx = searchSample( sample );
288  if( idx >= 0 ) {
289  m_samples.erase( m_samples.begin() + idx );
290  }
291 }
292 
293 // get instance
295  // create object (This is the only object.)
296  static ActiveObjectsManager mgr;
297 
298  return mgr;
299 }
300 
301 // @date 2011.08.24 <Add> M.Izumi ->
302 // SPEC 82165:Sample name mismatch (Close Dialog)
303 
304 // add tab sample
306  setTabSample();
307  m_tmpSamples.push_back( sample );
308 }
309 
310 // get
311 std::vector< Sample* > ActiveObjectsManager::getTabSamples(){
312  return m_tmpSamples;
313 }
314 
315 // set tag name
316 void ActiveObjectsManager::setSampleTagName( Sample* sample, const char* name ) {
317  if( name == NULL ) {
318  m_tagNameMap.erase( sample );
319  }
320  else {
321  m_tagNameMap[ sample ] = name;
322  }
323 }
324 
325 // get tag name
327  if( m_tagNameMap.find( sample ) == m_tagNameMap.end() ) {
328  return NULL;
329  }
330  return m_tagNameMap[ sample ].c_str();
331 }
332 
333 // del tab sample
335  int i = m_tmpSamples.size()-1;
336  while( i > -1 ){
337  if( m_tmpSamples[i] == sample ){
338  m_tmpSamples.erase( m_tmpSamples.begin() + i );
339  }
340  i--;
341  }
342  setTabSample();
343 }
344 
345 // set tab sample
347  std::vector< Sample* > strTmp;
348  strTmp = m_tmpSamples;
349  m_tmpSamples.clear();
350 
351  for( unsigned int i=0; i < strTmp.size(); i++ ){
352  m_tmpSamples.push_back( strTmp[i] );
353  }
354 }
355 // @date 2011.08.24 <Add> M.Izumi <-
356 
357 // @date 2011.10.03 <Add> M.Izumi ->
358 // get open spectra
359 std::vector< Spectrum* > ActiveObjectsManager::getOpenSpectra(){
360  return m_openSpectra;
361 }
362 
363 // add
365  if( spec != NULL ){
366  for( unsigned int i=0; i < m_openSpectra.size(); i++ ){
367  if( spec == m_openSpectra[i] ){
368  return;
369  }
370  }
371  m_openSpectra.push_back( spec );
372 
373  }
374 }
375 
376 // remove
378  if( spec != NULL ){
379  int iSize = m_openSpectra.size()-1;
380  while( iSize >= 0 ){
381  if( spec == m_openSpectra[iSize] ){
382  m_openSpectra.erase( m_openSpectra.begin() + iSize );
383  return;
384  }
385  iSize--;
386  }
387  }
388 }
389 // @date 2011.10.03 <Add> M.Izumi <-
interfaces of ActiveObjectsManager class
group of spectrum management class
Definition: DataGroupNode.h:33
static MsppManager & getInstance()
gets MsppManager object (This is the only object.)
void getDataSet(DataSet *dataSet)
gets spectra that contains this group. (getSpectrum method cannot get spectra that belong to child gr...
interfaces of Chromatogram class
void removeOpenSpectra(Spectrum *spec)
on closed spectrum canvas ( remove spectrum )
virtual void onCloseSample(Sample *sample, const bool deleting)
This method is called when a sample is closed. (override method)
sample information management class
Definition: Sample.h:34
std::map< Sample *, std::string > m_tagNameMap
Mass++ manager class.
Definition: MsppManager.h:28
virtual void onOpenSample(Sample *sample)
This method is called when a sample is opened. (override method)
IniFile * getIniFile()
gets ini file
static ActiveObjectsManager & getInstance()
get active object manager object (This is the only object.)
active object management class
std::vector< Spectrum * > getOpenSpectra()
const char * getString(const char *section, const char *key, const char *defaultValue)
gets string value
Definition: IniFile.cpp:78
interfaces of SampleSet class
virtual void removeChromatogram(Chromatogram *chrom)
removes chromatogram
Definition: DataSet.cpp:222
interfaces of Spectrum class
void removeHistoryFile(const char *path)
removes history file
interfaces of DataGroupNode class
interfaces of Sample class
Chromatogram * getChromatogram(const unsigned int index)
gets chroamtogram
Definition: DataSet.cpp:146
interfaces of GraphInfo class
unsigned int getNumberOfOpenedSamples()
gets the number of opened samples
void clearFileHistory()
clears file history
void setActiveSample(Sample *sample)
sets the active sample
void readHistoryFromIni()
reads history files from ini file
#define NULL
Definition: CoreMacros.h:18
std::vector< Spectrum * > m_openSpectra
void addOpenSpectra(Spectrum *spec)
Get Open spectra.
void addTabSample(Sample *sample)
adds opened sample
std::vector< std::string > m_fileHistory
unsigned int getNumberOfHistoryFiles()
gets the number of history files
unsigned int getNumberOfChromatograms()
gets the number of chromatograms
Definition: DataSet.cpp:141
void setTabSample()
initializes the array of opened samples
std::vector< Sample * > getTabSamples()
gets the array of opened samples
DataSet * getFilteredDataSet(Sample *sample)
gets filtered data set
bool isAutoCreated()
gets auto created flag value
int searchSample(Sample *sample)
searchs sample from array
void setSampleTagName(Sample *sample, const char *name)
sets the sample tag name
DataGroupNode * getRootDataGroupNode()
gets root spectrum group
Definition: Sample.cpp:219
void delTabSample(Sample *sample)
deletes opened sample
Sample * getActiveSample()
gets the active sample
spectrum information management class
Definition: Spectrum.h:30
std::string absolutepath(const char *path)
get absolute path
std::map< Sample *, DataSet * > m_filteredDataSetMap
one or more spectra management class
Definition: DataSet.h:31
void deleteValue(const char *section, const char *key)
deletes value
Definition: IniFile.cpp:277
ini file management class
Definition: IniFile.h:30
Sample * getOpenedSample(const unsigned int idx)
gets opened sample
chromatogram information management class
Definition: Chromatogram.h:33
const char * getHistoryFile(const unsigned int idx)
gets history file
const char * getSampleTagName(Sample *sample)
gets the sample tag name
void addHistoryFile(const char *path)
adds history file
void setString(const char *section, const char *key, const char *value)
sets string value
Definition: IniFile.cpp:64