Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
PointsManager.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "PointsManager.h"
14 
15 #include "Spectrum.h"
16 #include "Chromatogram.h"
17 #include "Sample.h"
18 #include "XYDataOperation.h"
19 #include "DataMapInfo.h"
20 
21 #include <set>
22 
23 
24 using namespace kome::objects;
25 
26 
27 #include <crtdbg.h>
28 #ifdef _DEBUG
29  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
30  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
31 #endif // _DEBUG
32 
33 
34 
35 // construcotr
37 }
38 
39 // destructor
41  // delete operation
42  for( std::map< XYDataOperation*, int >::iterator it = m_countMap.begin();
43  it != m_countMap.end(); it++ ) {
44  delete (*it).first;
45  }
46  m_countMap.clear();
47 }
48 
49 // get xy data of specified spectrum
51  // points
53 
54  // get points
55  if( dps.getLength() == 0 ) {
56  spec->getXYData( &dps, true );
57  }
58 
59  return &dps;
60 }
61 
62 // get xy data of specified chromatogram
64  // points
66 
67  // get points
68  if( dps.getLength() == 0 ) {
69  chrom->getXYData( &dps, true );
70  }
71 
72  return &dps;
73 }
74 
75 
76 // delete xy data of specified spectrum
78  // check the map
79  if( m_specPointsMap.find( spec ) == m_specPointsMap.end() ) {
80  return;
81  }
82 
83  // clear
85  dps.clearPoints();
86 
87  // erase
88  m_specPointsMap.erase( spec );
89 }
90 
91 // delete xy data of specified chromatogram
93  // check the map
94  if( m_chromPointsMap.find( chrom ) == m_chromPointsMap.end() ) {
95  return;
96  }
97 
98  // clear
100  dps.clearPoints();
101 
102  // erase
103  m_chromPointsMap.erase( chrom );
104 }
105 
106 
107 // adds operation
109  // check parameters
110  if( spec == NULL || operation == NULL ) {
111  return;
112  }
113 
114  // add count
115  if( m_countMap.find( operation ) == m_countMap.end() ) {
116  m_countMap[ operation ] = 1;
117  }
118  else {
119  int count = m_countMap[ operation ];
120  count++;
121  m_countMap[ operation ] = count;
122  }
123 
124  // add operation
125  m_specOperationMap[ spec ].push_back( operation );
126 
127  // sort
128  if( operation->getIndex() != -1 ){
129  std::sort( m_specOperationMap[spec].begin(), m_specOperationMap[spec].end(), lessOperation );
130  }
131 
132  // clear points
133  deleteXYData( spec );
134 }
135 
136 // add operation
138  // check parameters
139  if( chrom == NULL || operation == NULL ) {
140  return;
141  }
142 
143  // add count
144  if( m_countMap.find( operation ) == m_countMap.end() ) {
145  m_countMap[ operation ] = 1;
146  }
147  else {
148  int count = m_countMap[ operation ];
149  count++;
150  m_countMap[ operation ] = count;
151  }
152 
153  // add operation
154  m_chromOperationMap[ chrom ].push_back( operation );
155 
156  // sort
157  if( operation->getIndex() != -1 ){
158  std::sort( m_chromOperationMap[ chrom ].begin(), m_chromOperationMap[ chrom ].end(), lessOperation );
159  }
160  // clear points
161  deleteXYData( chrom );
162 }
163 
164 // add operation
166  // check parameters
167  if( sample == NULL || operation == NULL ){
168  return;
169  }
170 
171  // add count
172  if( m_countMap.find( operation ) == m_countMap.end() ){
173  m_countMap[ operation] = 1;
174  }else{
175  int count = m_countMap[ operation ];
176  count++;
177  m_countMap[ operation ] = count;
178  }
179 
180  // add operation
181  m_sampleOperationMap[ sample ].push_back( operation );
182 
183  if( operation->getIndex() != -1 ){
184  std::sort( m_sampleOperationMap[ sample ].begin(), m_sampleOperationMap[ sample ].end(), lessOperation );
185  }
186 }
187 
188 // remove operation of specified spectrum
190  // check parameters
191  if( spec == NULL || operation == NULL ) {
192  return;
193  }
194 
195  // search
196  if( m_specOperationMap.find( spec ) == m_specOperationMap.end() ) {
197  return;
198  }
199  std::vector< XYDataOperation* >& operations = m_specOperationMap[ spec ];
200  int idx = -1;
201 
202  for( int i = 0; i < (int)operations.size() && idx < 0; i++ ) {
203  if( operations[ i ] == operation ) {
204  idx = i;
205  }
206  }
207  if( idx < 0 ) {
208  return;
209  }
210 
211  // remove operation
212  operations.erase( operations.begin() + idx );
213 
214  // sort
215  if( operations.size() == 0 ) {
216  m_specOperationMap.erase( spec );
217  }
218 
219  deleteOperation( operation );
220 }
221 
222 // remove operation of specified chromatogram
224  // check parameters
225  if( chrom == NULL || operation == NULL ) {
226  return;
227  }
228 
229  // search
230  if( m_chromOperationMap.find( chrom ) == m_chromOperationMap.end() ) {
231  return;
232  }
233  std::vector< XYDataOperation* >& operations = m_chromOperationMap[ chrom ];
234  int idx = -1;
235 
236  for( int i = 0; i < (int)operations.size() && idx < 0; i++ ) {
237  if( operations[ i ] == operation ) {
238  idx = i;
239  }
240  }
241  if( idx < 0 ) {
242  return;
243  }
244 
245  // remove operation
246  operations.erase( operations.begin() + idx );
247  if( operations.size() == 0 ) {
248  m_chromOperationMap.erase( chrom );
249  }
250 
251  deleteOperation( operation );
252 }
253 
254 // remove operation of specified sample
256  // check parameters
257  if( sample == NULL || operation == NULL ){
258  return;
259  }
260 
261  // search
262  if( m_sampleOperationMap.find( sample) == m_sampleOperationMap.end() ){
263  return;
264  }
265  std::vector< XYDataOperation* >& operations = m_sampleOperationMap[ sample ];
266  int idx = -1;
267 
268  for( int i=0; i < (int)operations.size() && idx < 0; i++ ){
269  if( operations[ i ] == operation ){
270  idx = i;
271  }
272  }
273  if( idx < 0 ){
274  return;
275  }
276 
277  // remove operation
278  operations.erase( operations.begin() + idx );
279  if( operations.size() == 0 ){
280  m_sampleOperationMap.erase( sample );
281  }
282 
283  deleteOperation( operation );
284 }
285 
286 
287 // clear operations of specified spectrum
289  // check the parameter
290  if( spec == NULL ) {
291  return;
292  }
293 
294  // operations
295  if( m_specOperationMap.find( spec ) == m_specOperationMap.end() ) {
296  return;
297  }
298  std::vector< XYDataOperation* >& operations = m_specOperationMap[ spec ];
299 
300  // delete operations
301  for( unsigned int i = 0; i < operations.size(); i++ ) {
302  deleteOperation( operations[ i ] );
303  }
304 
305  // erase
306  operations.clear();
307  m_specOperationMap.erase( spec );
308 }
309 
310 // clear operations of specified chromatogram
312  // check the parameter
313  if( chrom == NULL ) {
314  return;
315  }
316 
317  // operations
318  if( m_chromOperationMap.find( chrom ) == m_chromOperationMap.end() ) {
319  return;
320  }
321  std::vector< XYDataOperation* >& operations = m_chromOperationMap[ chrom ];
322 
323  // delete oprations
324  for( unsigned int i = 0; i < operations.size(); i++ ) {
325  deleteOperation( operations[ i ] );
326  }
327 
328  // erase
329  operations.clear();
330  m_chromOperationMap.erase( chrom );
331 }
332 
333 // clear operations of specified sample
335  // check the parameter
336  if( sample == NULL ){
337  return;
338  }
339 
340  //operations
341  if( m_sampleOperationMap.find( sample) == m_sampleOperationMap.end() ){
342  return;
343  }
344  std::vector< XYDataOperation* >& operations = m_sampleOperationMap[ sample ];
345 
346  // delete operations
347  for( unsigned int i=0; i < operations.size(); i++ ){
348  deleteOperation( operations[ i ] );
349  }
350 
351  // erase
352  operations.clear();
353  m_sampleOperationMap.erase( sample );
354 }
355 
356 // get the number of operations of specified spectrum
358  // check the parameter
359  if( spec == NULL ) {
360  return 0;
361  }
362 
363  // get size
364  if( m_specOperationMap.find( spec ) == m_specOperationMap.end() ) {
365  return 0;
366  }
367  return m_specOperationMap[ spec ].size();
368 }
369 
370 // get the number of operations of specified chromatogram
372  // check the parameter
373  if( chrom == NULL ) {
374  return 0;
375  }
376 
377  // get size
378  if( m_chromOperationMap.find( chrom ) == m_chromOperationMap.end() ) {
379  return 0;
380  }
381  return m_chromOperationMap[ chrom ].size();
382 }
383 
384 // get the number of operations of specified chromatogram
386  // check the parameter
387  if( sample == NULL ){
388  return 0;
389  }
390 
391  // get size
392  if( m_sampleOperationMap.find( sample) == m_sampleOperationMap.end() ){
393  return 0;
394  }
395  return m_sampleOperationMap[ sample ].size();
396 }
397 
398 // get operation of specified spectrum
399 XYDataOperation* PointsManager::getOperation( Spectrum* spec, const unsigned int index ) {
400  // check the parameter
401  if( spec == NULL ) {
402  return NULL;
403  }
404 
405  // operations
406  if( m_specOperationMap.find( spec ) == m_specOperationMap.end() ) {
407  return NULL;
408  }
409  std::vector< XYDataOperation* >& operations = m_specOperationMap[ spec ];
410 
411  // check the index
412  if( index >= operations.size() ) {
413  return NULL;
414  }
415  return operations[ index ];
416 }
417 
418 // get operation of specified chromatogram
419 XYDataOperation* PointsManager::getOperation( Chromatogram* chrom, const unsigned int index ) {
420  // check the parameter
421  if( chrom == NULL ) {
422  return NULL;
423  }
424 
425  // operations
426  if( m_chromOperationMap.find( chrom ) == m_chromOperationMap.end() ) {
427  return NULL;
428  }
429  std::vector< XYDataOperation* >& operations = m_chromOperationMap[ chrom ];
430 
431  // check the index
432  if( index >= operations.size() ) {
433  return NULL;
434  }
435  return operations[ index ];
436 }
437 
438 // get operation of specified sample
439 XYDataOperation* PointsManager::getOperation( Sample* sample, const unsigned int index ){
440  // check the parameter
441  if( sample == NULL ){
442  return NULL;
443  }
444 
445  // operations
446  if( m_sampleOperationMap.find( sample ) == m_sampleOperationMap.end() ){
447  return NULL;
448  }
449  std::vector< XYDataOperation* >& operations = m_sampleOperationMap[ sample ];
450 
451  // check the index
452  if( index >= operations.size() ){
453  return NULL;
454  }
455  return operations[ index ];
456 }
457 
458 // delete operation
460  // check parameter
461  if( operation == NULL || m_countMap.find( operation ) == m_countMap.end() ) {
462  return;
463  }
464 
465  // get count
466  int count = m_countMap[ operation ];
467  count--;
468  if( count > 0 ) {
469  m_countMap[ operation ] = count;
470  }
471  else {
472  m_countMap.erase( operation );
473  delete operation;
474  }
475 }
476 
477 // This method is called when a sample is closed
478 void PointsManager::onCloseSample( Sample* sample, const bool deleting ) {
479  // get spectra
480  std::set< Spectrum* > specSet;
481  for( std::map< Spectrum*, kome::core::DataPoints >::iterator it = m_specPointsMap.begin();
482  it != m_specPointsMap.end(); it++ ) {
483  Spectrum* spec = (*it).first;
484  if( spec->getSample() == sample ) {
485  specSet.insert( spec );
486  }
487  }
488  for( std::map< Spectrum*, std::vector< XYDataOperation* > >::iterator it = m_specOperationMap.begin();
489  it != m_specOperationMap.end(); it++ ) {
490  Spectrum* spec = (*it).first;
491  if( spec->getSample() == sample ) {
492  specSet.insert( spec );
493  }
494  }
495 
496  // delete spectra
497  for( std::set< Spectrum* >::iterator it = specSet.begin(); it != specSet.end(); it++ ) {
498  // spectrum
499  Spectrum* spec = *it;
500 
501  // delete operation
502  if( m_specOperationMap.find( spec ) != m_specOperationMap.end() ) {
503  std::vector< XYDataOperation* >& operations = m_specOperationMap[ spec ];
504  for( unsigned int i = 0; i < operations.size(); i++ ) {
505  deleteOperation( operations[ i ] );
506  }
507 
508  m_specOperationMap.erase( spec );
509  }
510 
511  // delete points
512  if( m_specPointsMap.find( spec ) != m_specPointsMap.end() ) {
513  m_specPointsMap.erase( spec );
514  }
515  }
516 
517  // get chromatograms
518  std::set< Chromatogram* > chromSet;
519  for( std::map< Chromatogram*, kome::core::DataPoints >::iterator it = m_chromPointsMap.begin();
520  it != m_chromPointsMap.end(); it++ ) {
521  Chromatogram* chrom = (*it).first;
522  if( chrom->getSample() == sample ) {
523  chromSet.insert( chrom );
524  }
525  }
526  for( std::map< Chromatogram*, std::vector< XYDataOperation* > >::iterator it = m_chromOperationMap.begin();
527  it != m_chromOperationMap.end(); it++ ) {
528  Chromatogram* chrom = (*it).first;
529  if( chrom->getSample() == sample ) {
530  chromSet.insert( chrom );
531  }
532  }
533 
534  // delete chromatograms
535  for( std::set< Chromatogram* >::iterator it = chromSet.begin(); it != chromSet.end(); it++ ) {
536  // chromatogram
537  Chromatogram* chrom = *it;
538 
539  // delete operation
540  if( m_chromOperationMap.find( chrom ) != m_chromOperationMap.end() ) {
541  std::vector< XYDataOperation* >& operations = m_chromOperationMap[ chrom ];
542  for( unsigned int i = 0; i < operations.size(); i++ ) {
543  deleteOperation( operations[ i ] );
544  }
545 
546  m_chromOperationMap.erase( chrom );
547  }
548 
549  // delete points
550  if( m_chromPointsMap.find( chrom ) != m_chromPointsMap.end() ) {
551  m_chromPointsMap.erase( chrom );
552  }
553  }
554 }
555 
556 // on close spectrum
557 void PointsManager::onCloseSpectrum( kome::objects::Spectrum* spec, const bool deleting ) {
558  deleteXYData( spec );
559 }
560 
561 // on close Chromatogram
563  deleteXYData( chrom );
564 }
565 
566 // less operation
568  return ( opt0->getIndex() < opt1->getIndex() );
569 }
570 
571 
572 // get points manager object
574  // create object (This is the only object.)
575  static PointsManager mgr;
576 
577  return mgr;
578 }
abstraction class of two dimention coordinate data
Definition: XYData.h:34
virtual ~PointsManager()
destructor
Sample * getSample()
gets the sample that has this spectrum
Definition: Spectrum.cpp:108
data points data of profile management class
Definition: DataPoints.h:25
interfaces of PointsManager class
unsigned int getNumberOfOperations(Spectrum *spec)
gets the number of operations of specified spectrum
interfaces of Chromatogram class
virtual void onCloseChromatogram(Chromatogram *chrom, const bool deleting)
This method is called when a chromatogram is closed. (override method)
sample information management class
Definition: Sample.h:34
Sample * getSample()
gets sample
std::map< Spectrum *, kome::core::DataPoints > m_specPointsMap
Definition: PointsManager.h:55
std::map< Spectrum *, std::vector< XYDataOperation * > > m_specOperationMap
Definition: PointsManager.h:64
void deleteOperation(XYDataOperation *operation)
deletes operation object
void clearOperations(Spectrum *spec)
clears data operation of specified spectrum
std::map< Sample *, std::vector< XYDataOperation * > > m_sampleOperationMap
Definition: PointsManager.h:70
void clearPoints()
clear all data points
Definition: XYData.cpp:137
static PointsManager & getInstance()
get data points manager object (This is the only object.)
data points management class
Definition: PointsManager.h:36
interfaces of Spectrum class
virtual void onCloseSpectrum(Spectrum *spec, const bool deleting)
This method is called when a spectrum is closed. (override method)
interfaces of XYDataOperation class
interfaces of Sample class
static bool lessOperation(XYDataOperation *opt0, XYDataOperation *opt1)
compare index of XYDataOperation to sort
interfaces of GraphInfo class
std::map< Chromatogram *, std::vector< XYDataOperation * > > m_chromOperationMap
Definition: PointsManager.h:67
kome::core::XYData * getXYData()
gets xy data from data manager
#define NULL
Definition: CoreMacros.h:18
kome::core::XYData * getXYData()
gets xy data from data manager
Definition: Spectrum.cpp:279
void removeOperation(Spectrum *spec, XYDataOperation *operation)
removes data operation from specified spectrum
virtual void onCloseSample(Sample *sample, const bool deleting)
This method is called when a sample is closed. (override method)
void addOperation(Spectrum *spec, XYDataOperation *operation)
adds data operation to specified spectrum
std::map< XYDataOperation *, int > m_countMap
Definition: PointsManager.h:52
kome::core::XYData * getXYData(Spectrum *spec)
gets xy data of specified spectrum
spectrum information management class
Definition: Spectrum.h:30
void deleteXYData(Spectrum *spec)
deletes xy data of specified spectrum
std::map< Chromatogram *, kome::core::DataPoints > m_chromPointsMap
Definition: PointsManager.h:58
XYDataOperation * getOperation(Spectrum *spec, const unsigned int index)
gets operation of specified spectrum
chromatogram information management class
Definition: Chromatogram.h:33
xy data operation class
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216