GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBTableWidgetContainer.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
35 #include <iostream>
36 #include <cstdlib>
37 
39  std::string iCollectionName,
40  int iImgSessionID)
41 {
42  m_CollectionName = iCollectionName;
44  m_CollectionIDName += "ID";
45  m_TracesName = iTracesName;
47  m_TracesIDName += "ID";
48  m_ImgSessionID = iImgSessionID;
49 }
50 
51 //--------------------------------------------------------------------------
52 
53 //--------------------------------------------------------------------------
54 std::vector< GoDBTraceInfoForTableWidget >
56 {
58 
59  //IsSelected column will correspond to the "IsHighLighted":
60  temp.InfoName = "Selected";
61  temp.ColumnNameTableWidget = "";
62  temp.ToolTip = "Check/Uncheck ";
63  temp.ToolTip += this->m_TracesName;
64  m_ColumnsInfos.push_back(temp);
65  std::pair< GoDBTraceInfoForTableWidget, std::vector< std::string > > PairTemp;
66  PairTemp.first = temp;
67  m_RowContainer.push_back(PairTemp);
68  temp.Clear();
69 
70  //Get the info for the TraceID:
71  temp.InfoName = this->m_TracesIDName;
74  temp.TableNameDatabase = this->m_TracesName;
75  m_ColumnsInfos.push_back(temp);
76  PairTemp.first = temp;
77  m_RowContainer.push_back(PairTemp);
78  temp.Clear();
79 
80  //Get the info for the CollectionID:
81  if (this->m_CollectionName != "None")
82  {
83  temp.InfoName = this->m_CollectionIDName;
86  temp.TableNameDatabase = this->m_TracesName;
89  m_ColumnsInfos.push_back(temp);
90  PairTemp.first = temp;
91  m_RowContainer.push_back(PairTemp);
92  temp.Clear();
93  }
94 
95  //Get the info for the ColorID of the trace:
96  //check if it is needed in the query ??
97  std::string ColorTrace = this->m_TracesName;
98  ColorTrace += "Color";
99  temp.ColumnNameDatabase = "ColorID";
100  temp.TableNameDatabase = this->m_TracesName;
101  temp.InfoName = ColorTrace;
102  temp.TableForeignKeyDatabase = "ColorID";
103  temp.TableKeyDatabase = "ColorID";
104  m_ColumnsInfos.push_back(temp);
105  PairTemp.first = temp;
106  m_RowContainer.push_back(PairTemp);
107  temp.Clear();
108 
109  //Get the info for the Red value of the trace:
110  temp.ColumnNameDatabase = "Red";
111  temp.TableNameDatabase = "color";
112  std::string OtherInfo = "RedFor";
113  OtherInfo += this->m_TracesName;
114  temp.InfoName = OtherInfo;
115  temp.TableForeignKeyDatabase = "ColorID";
116  temp.TableKeyDatabase = "ColorID";
117  m_ColumnsInfos.push_back(temp);
118  PairTemp.first = temp;
119  m_RowContainer.push_back(PairTemp);
120  temp.Clear();
121 
122  //Get the info for the Green value of the trace:
123  temp.ColumnNameDatabase = "Green";
124  temp.TableNameDatabase = "color";
125  OtherInfo = "GreenFor";
126  OtherInfo += this->m_TracesName;
127  temp.InfoName = OtherInfo;
128  temp.TableForeignKeyDatabase = "ColorID";
129  temp.TableKeyDatabase = "ColorID";
130  m_ColumnsInfos.push_back(temp);
131  PairTemp.first = temp;
132  m_RowContainer.push_back(PairTemp);
133  temp.Clear();
134 
135  //Get the info for the Blue value of the trace:
136  temp.ColumnNameDatabase = "Blue";
137  temp.TableNameDatabase = "color";
138  OtherInfo = "BlueFor";
139  OtherInfo += this->m_TracesName;
140  temp.InfoName = OtherInfo;
141  temp.TableForeignKeyDatabase = "ColorID";
142  temp.TableKeyDatabase = "ColorID";
143  m_ColumnsInfos.push_back(temp);
144  PairTemp.first = temp;
145  m_RowContainer.push_back(PairTemp);
146  temp.Clear();
147 
148  //Get the info for the Alpha value of the trace:
149  temp.ColumnNameDatabase = "Alpha";
150  temp.TableNameDatabase = "color";
151  OtherInfo = "AlphaFor";
152  OtherInfo += this->m_TracesName;
153  temp.InfoName = OtherInfo;
154  temp.TableForeignKeyDatabase = "ColorID";
155  temp.TableKeyDatabase = "ColorID";
156  m_ColumnsInfos.push_back(temp);
157  PairTemp.first = temp;
158  m_RowContainer.push_back(PairTemp);
159  temp.Clear();
160 
161  //Get the info for the ColorID of the collection:
162  if (this->m_CollectionName != "None")
163  {
164  std::string ColorCollection = this->m_CollectionName;
165  ColorCollection += "Color";
166  temp.ColumnNameDatabase = "ColorID";
167  temp.TableNameDatabase = this->m_CollectionName;
168  temp.InfoName = ColorCollection;
171  temp.SameFieldForDifferentValues = false;
172  m_ColumnsInfos.push_back(temp);
173  PairTemp.first = temp;
174  m_RowContainer.push_back(PairTemp);
175  temp.Clear();
176 
177  //Get the info for the Red value of the collection:
178  temp.ColumnNameDatabase = "Red";
179  temp.TableNameDatabase = "color";
180  OtherInfo = "RedFor";
181  OtherInfo += this->m_CollectionName;
183  temp.InfoName = OtherInfo;
184  temp.TableForeignKeyDatabase = "ColorID";
185  temp.TableKeyDatabase = "ColorID";
186  temp.SameFieldForDifferentValues = true;
187  m_ColumnsInfos.push_back(temp);
188  PairTemp.first = temp;
189  m_RowContainer.push_back(PairTemp);
190  temp.Clear();
191 
192  //Get the info for the Green value of the collection:
193  temp.ColumnNameDatabase = "Green";
194  temp.TableNameDatabase = "color";
195  OtherInfo = "GreenFor";
196  OtherInfo += this->m_CollectionName;
198  temp.InfoName = OtherInfo;
199  temp.TableForeignKeyDatabase = "ColorID";
200  temp.TableKeyDatabase = "ColorID";
201  temp.SameFieldForDifferentValues = true;
202  m_ColumnsInfos.push_back(temp);
203  PairTemp.first = temp;
204  m_RowContainer.push_back(PairTemp);
205  temp.Clear();
206 
207  //Get the info for the Blue value of the collection:
208  temp.ColumnNameDatabase = "Blue";
209  temp.TableNameDatabase = "color";
210  OtherInfo = "BlueFor";
211  OtherInfo += this->m_CollectionName;
213  temp.InfoName = OtherInfo;
214  temp.TableForeignKeyDatabase = "ColorID";
215  temp.TableKeyDatabase = "ColorID";
216  temp.SameFieldForDifferentValues = true;
217  m_ColumnsInfos.push_back(temp);
218  PairTemp.first = temp;
219  m_RowContainer.push_back(PairTemp);
220  temp.Clear();
221 
222  //Get the info for the Alpha value of the collection:
223  temp.ColumnNameDatabase = "Alpha";
224  temp.TableNameDatabase = "color";
225  OtherInfo = "AlphaFor";
226  OtherInfo += this->m_CollectionName;
228  temp.InfoName = OtherInfo;
229  temp.TableForeignKeyDatabase = "ColorID";
230  temp.TableKeyDatabase = "ColorID";
231  temp.SameFieldForDifferentValues = true;
232  m_ColumnsInfos.push_back(temp);
233  PairTemp.first = temp;
234  m_RowContainer.push_back(PairTemp);
235  temp.Clear();
236  }
237 
239  //Get the info for the PCoord:
240  temp.InfoName = "PCoord";
241  temp.ColumnNameDatabase = "PCoord";
242  temp.ColumnNameTableWidget = "Plate";
243  temp.TableNameDatabase = "coordinate";
244  temp.TableForeignKeyDatabase = "CoordIDMin";
245  temp.TableKeyDatabase = "CoordID";
246  m_ColumnsInfos.push_back(temp);
247  PairTemp.first = temp;
248  m_RowContainer.push_back(PairTemp);
249  temp.Clear();
250 
251  //Get the info for the RCoord:
252  temp.InfoName = "RCoord";
253  temp.ColumnNameDatabase = "RCoord";
254  temp.ColumnNameTableWidget = "Row";
255  temp.TableNameDatabase = "coordinate";
256  temp.TableForeignKeyDatabase = "CoordIDMin";
257  temp.TableKeyDatabase = "CoordID";
258  m_ColumnsInfos.push_back(temp);
259  PairTemp.first = temp;
260  m_RowContainer.push_back(PairTemp);
261  temp.Clear();
262 
263  //Get the info for the CCoord:
264  temp.InfoName = "CCoord";
265  temp.ColumnNameDatabase = "CCoord";
266  temp.ColumnNameTableWidget = "Column";
267  temp.TableNameDatabase = "coordinate";
268  temp.TableForeignKeyDatabase = "CoordIDMin";
269  temp.TableKeyDatabase = "CoordID";
270  m_ColumnsInfos.push_back(temp);
271  PairTemp.first = temp;
272  m_RowContainer.push_back(PairTemp);
273  temp.Clear();
274 
275  //Get the info for the XTile:
276  temp.InfoName = "XTile";
277  temp.ColumnNameDatabase = "XTileCoord";
278  temp.ColumnNameTableWidget = "XTile";
279  temp.TableNameDatabase = "coordinate";
280  temp.TableForeignKeyDatabase = "CoordIDMin";
281  temp.TableKeyDatabase = "CoordID";
282  m_ColumnsInfos.push_back(temp);
283  PairTemp.first = temp;
284  m_RowContainer.push_back(PairTemp);
285  temp.Clear();
286 
287  //Get the info for the YTile:
288  temp.InfoName = "YTile";
289  temp.ColumnNameDatabase = "YTileCoord";
290  temp.ColumnNameTableWidget = "YTile";
291  temp.TableNameDatabase = "coordinate";
292  temp.TableForeignKeyDatabase = "CoordIDMin";
293  temp.TableKeyDatabase = "CoordID";
294  m_ColumnsInfos.push_back(temp);
295  PairTemp.first = temp;
296  m_RowContainer.push_back(PairTemp);
297  temp.Clear();
298 
299  //Get the info for the ZTile:
300  temp.InfoName = "ZTile";
301  temp.ColumnNameDatabase = "ZTileCoord";
302  temp.ColumnNameTableWidget = "ZTile";
303  temp.TableNameDatabase = "coordinate";
304  temp.TableForeignKeyDatabase = "CoordIDMin";
305  temp.TableKeyDatabase = "CoordID";
306  m_ColumnsInfos.push_back(temp);
307  PairTemp.first = temp;
308  m_RowContainer.push_back(PairTemp);
309  temp.Clear();
310 
311  //Get the info for the CoordIDMin of the bounding box:
312  temp.InfoName = "BDCoordIDMin";
313  temp.ColumnNameDatabase = "CoordIDMin";
314  temp.TableNameDatabase = this->m_TracesName;
315  temp.TableForeignKeyDatabase = "CoordIDMin";
316  temp.TableKeyDatabase = "CoordID";
317  m_ColumnsInfos.push_back(temp);
318  PairTemp.first = temp;
319  m_RowContainer.push_back(PairTemp);
320  temp.Clear();
321 
322  //Get the info for the XMin:
323  temp.InfoName = "BDXMin";
324  temp.ColumnNameDatabase = "XCoord";
325  temp.ColumnNameTableWidget = "XMin";
326  temp.TableNameDatabase = "coordinate";
327  temp.TableForeignKeyDatabase = "CoordIDMin";
328  temp.TableKeyDatabase = "CoordID";
329  m_ColumnsInfos.push_back(temp);
330  PairTemp.first = temp;
331  m_RowContainer.push_back(PairTemp);
332  temp.Clear();
333 
334  //Get the info for the YMin:
335  temp.InfoName = "BDYMin";
336  temp.ColumnNameDatabase = "YCoord";
337  temp.ColumnNameTableWidget = "YMin";
338  temp.TableNameDatabase = "coordinate";
339  temp.TableForeignKeyDatabase = "CoordIDMin";
340  temp.TableKeyDatabase = "CoordID";
341  m_ColumnsInfos.push_back(temp);
342  PairTemp.first = temp;
343  m_RowContainer.push_back(PairTemp);
344  temp.Clear();
345 
346  //Get the info for the ZMin:
347  temp.InfoName = "BDZMin";
348  temp.ColumnNameDatabase = "ZCoord";
349  temp.ColumnNameTableWidget = "ZMin";
350  temp.TableNameDatabase = "coordinate";
351  temp.TableForeignKeyDatabase = "CoordIDMin";
352  temp.TableKeyDatabase = "CoordID";
353  m_ColumnsInfos.push_back(temp);
354  PairTemp.first = temp;
355  m_RowContainer.push_back(PairTemp);
356  temp.Clear();
357 
358  //Get the info for the CoordIDMax of the bounding box:
359  temp.InfoName = "BDCoordIDMax";
360  temp.ColumnNameDatabase = "CoordIDMax";
361  temp.TableNameDatabase = this->m_TracesName;
362  temp.TableForeignKeyDatabase = "CoordIDMax";
363  temp.TableKeyDatabase = "CoordID";
364  m_ColumnsInfos.push_back(temp);
365  PairTemp.first = temp;
366  m_RowContainer.push_back(PairTemp);
367  temp.Clear();
368 
369  //Get the info for the XMax:
370  temp.InfoName = "BDXMax";
371  temp.ColumnNameDatabase = "XCoord";
372  temp.ColumnNameTableWidget = "XMax";
373  temp.TableNameDatabase = "coordinate";
374  temp.TableForeignKeyDatabase = "CoordIDMax";
375  temp.TableKeyDatabase = "CoordID";
376  temp.SameFieldForDifferentValues = true;
377  m_ColumnsInfos.push_back(temp);
378  PairTemp.first = temp;
379  m_RowContainer.push_back(PairTemp);
380  temp.Clear();
381 
382  //Get the info for the YMax:
383  temp.InfoName = "BDYMax";
384  temp.ColumnNameDatabase = "YCoord";
385  temp.ColumnNameTableWidget = "YMax";
386  temp.TableNameDatabase = "coordinate";
387  temp.TableForeignKeyDatabase = "CoordIDMax";
388  temp.TableKeyDatabase = "CoordID";
389  temp.SameFieldForDifferentValues = true;
390  m_ColumnsInfos.push_back(temp);
391  PairTemp.first = temp;
392  m_RowContainer.push_back(PairTemp);
393  temp.Clear();
394 
395  //Get the info for the ZMax:
396  temp.InfoName = "BDZMax";
397  temp.ColumnNameDatabase = "ZCoord";
398  temp.ColumnNameTableWidget = "ZMax";
399  temp.TableNameDatabase = "coordinate";
400  temp.TableForeignKeyDatabase = "CoordIDMax";
401  temp.TableKeyDatabase = "CoordID";
402  temp.SameFieldForDifferentValues = true;
403  m_ColumnsInfos.push_back(temp);
404  PairTemp.first = temp;
405  m_RowContainer.push_back(PairTemp);
406  temp.Clear();
407 
408  //this->SetCommonInfoForTwoTracesTable();
409 
410  return m_ColumnsInfos;
411 }
412 
413 //--------------------------------------------------------------------------
414 
415 //--------------------------------------------------------------------------
417 {
419 
420  std::pair< GoDBTraceInfoForTableWidget, std::vector< std::string > > PairTemp;
421  //for the column "is visible or not":
422  temp.InfoName = "Show";
423  temp.ColumnNameTableWidget = "Show";
424  m_ColumnsInfos.push_back(temp);
425  PairTemp.first = temp;
426  m_RowContainer.push_back(PairTemp);
427  temp.Clear();
428 }
429 
430 //--------------------------------------------------------------------------
431 
432 //--------------------------------------------------------------------------
433 std::list< std::pair< std::string, std::string > >
435 {
436  std::list< std::pair< std::string, std::string > > oListColumnNamesAndToolTips;
437  for ( unsigned int i = 0; i < m_ColumnsInfos.size(); i++ )
438  {
439  if ( m_ColumnsInfos[i].ColumnNameTableWidget != "None"
440  && m_ColumnsInfos[i].ColumnNameTableWidget != "NoneID" )
441  {
442  std::pair< std::string, std::string > temp;
443  temp.first = m_ColumnsInfos[i].ColumnNameTableWidget;
444  temp.second = m_ColumnsInfos[i].ToolTip;
445  oListColumnNamesAndToolTips.push_back(temp);
446  }
447  }
448  return oListColumnNamesAndToolTips;
449 }
450 
451 //--------------------------------------------------------------------------
452 
453 //--------------------------------------------------------------------------
455 {
456  std::vector< std::string > ListComputedColumnNames;
457  for ( unsigned int i = 0; i < m_ColumnsInfos.size(); i++ )
458  {
459  if ( m_ColumnsInfos[i].ColumnNameTableWidget != "None"
460  && m_ColumnsInfos[i].ColumnNameTableWidget != "NoneID"
461  && m_ColumnsInfos[i].ColumnNameDatabase == "None"
462  && m_ColumnsInfos[i].InfoName != "Selected" )
463  {
464  ListComputedColumnNames.push_back(m_ColumnsInfos[i].ColumnNameTableWidget);
465  }
466  }
467  return ListComputedColumnNames;
468 }
469 
470 //--------------------------------------------------------------------------
471 
472 //--------------------------------------------------------------------------
473 std::vector< std::string > GoDBTableWidgetContainer::GetQueryStringForSelectFieldsTables(bool SameFieldsInQuery)
474 {
475  std::vector< std::string > SelectFields;
476  unsigned int i = 0;
477  while ( i < m_ColumnsInfos.size() )
478  {
479  //if there is info to get from the database and to put directly in the
480  //table widget, and that the column Name in the table widget is not "NoneID"
481  // (that can be found in the lineage table):
482  if ( m_ColumnsInfos[i].ColumnNameDatabase != "None"
483  && //m_ColumnsInfos[i].ColumnNameTableWidget != "None" &&
484  m_ColumnsInfos[i].SameFieldForDifferentValues == SameFieldsInQuery
485  && m_ColumnsInfos[i].ColumnNameTableWidget != "NoneID"
486  && m_ColumnsInfos[i].TableNameDatabase != "None"
487  && m_ColumnsInfos[i].TableNameDatabase != "intensity" )
488  {
489  //record TableNameDatabase.ColumnNameDatabase if it is not already in the
490  // vector:
491  std::string temp = m_ColumnsInfos[i].TableNameDatabase;
492  temp += ".";
493  temp += m_ColumnsInfos[i].ColumnNameDatabase;
494  bool IsSelectFieldsInTheVector = false;
495  unsigned int j = 0;
496  while ( IsSelectFieldsInTheVector == false && j < SelectFields.size() )
497  {
498  if ( SelectFields[j] == temp )
499  {
500  IsSelectFieldsInTheVector = true;
501  }
502  j++;
503  }
504  if ( IsSelectFieldsInTheVector == false )
505  {
506  SelectFields.push_back(temp);
507  }
508  }
509  i++;
510  }
511  return SelectFields;
512 }
513 
514 //--------------------------------------------------------------------------
515 
516 //--------------------------------------------------------------------------
518  std::vector< std::vector< std::string > > iResultsFromQuery,
519  std::vector< std::string > iSelectFields, std::string BaseOn)
520 {
521  for ( size_t i = 0; i < iSelectFields.size(); i++ )
522  {
523  bool HasBeenFound = false;
524  for ( size_t j = 0; j < m_RowContainer.size() && HasBeenFound == false; j++ )
525  {
526  std::string test = iSelectFields[i]; //for test
527  // purpose
528  std::string test2 = m_RowContainer[j].first.ColumnNameDatabase; //for test
529  // purpose
530  size_t PosColumnNameFound;
531  if ( BaseOn.empty() )
532  {
533  PosColumnNameFound =
534  iSelectFields[i].find(m_RowContainer[j].first.ColumnNameDatabase);
535  }
536  else
537  {
538  if ( BaseOn == "ColumnNameTableWidget" )
539  {
540  std::string NameColumn = m_RowContainer[j].first.ColumnNameTableWidget;
541  if ( !NameColumn.empty() )
542  {
543  PosColumnNameFound =
544  iSelectFields[i].find(NameColumn);
545  }
546  else
547  {
548  PosColumnNameFound = std::string::npos;
549  }
550  }
551  else
552  {
553  std::cout << "The BaseOn you choose doesn't exist" << std::endl;
554  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
555  std::cout << std::endl;
556  return;
557  }
558  }
559  if ( PosColumnNameFound != std::string::npos && m_RowContainer[j].second.empty() )
560  {
561  HasBeenFound = true;
562  for ( size_t RowNumberForQueryResults = 0;
563  RowNumberForQueryResults < iResultsFromQuery.size();
564  ++RowNumberForQueryResults )
565  {
566  std::vector< std::string > ResultsFromQueryForOneTrace =
567  iResultsFromQuery[RowNumberForQueryResults];
568  //j found corresponds to the vector in the row_container to be filled
569  //with the values from the results of the query corresponding to i
570  // column:
571  m_RowContainer[j].second.push_back(ResultsFromQueryForOneTrace[i]);
572  }
573  }
574  }
575  }
576 }
577 
578 //--------------------------------------------------------------------------
579 
580 //--------------------------------------------------------------------------
581 std::vector< std::string > GoDBTableWidgetContainer::GetQueryStringForTraceJoinedTables(bool SameFieldsInQuery)
582 {
583  std::list< std::string > SelectNamesColumns;
584  std::vector< std::string > SelectJoinTables;
585  unsigned int i = 0;
586  //for all the TableNameDatabase in the m_ColumnsInfos:
587  while ( i < m_ColumnsInfos.size() )
588  {
589  std::string name = m_ColumnsInfos[i].TableNameDatabase; //for test purpose
590  std::string name2 = m_ColumnsInfos[i].ColumnNameDatabase; //for test purpose
591  //check first that the ColumnsInfos has direct infosfrom the database:
592  if ( m_ColumnsInfos[i].TableNameDatabase != "None"
593  && m_ColumnsInfos[i].TableNameDatabase != "intensity" )
594  {
595  //check that the table is not already in the list:
596  std::vector< std::string >::iterator iter = SelectJoinTables.begin();
597  bool IsTableInTheList = false;
598  while ( iter != SelectJoinTables.end() && IsTableInTheList == false )
599  {
600  if ( *iter == m_ColumnsInfos[i].TableNameDatabase )
601  {
602  IsTableInTheList = true;
603  }
604  ++iter;
605  }
606  //if the table is not in the list,is not the table of the trace and
607  //is accessed during the first query, record the name of the table,
608  //and the traceName.tableforeignkey = tableName.primarykey for the
609  // "on" condition in the "Join" part of the query
610  if ( IsTableInTheList == false
611  && m_ColumnsInfos[i].TableNameDatabase != this->m_TracesName
612  && m_ColumnsInfos[i].SameFieldForDifferentValues == SameFieldsInQuery )
613  {
614  if ( m_ColumnsInfos[i].AccessFromTraceTableThroughWhichTable == "None" )
615  {
616  SelectJoinTables.push_back(m_ColumnsInfos[i].TableNameDatabase);
617  std::string OnQuery = this->m_TracesName;
618  OnQuery += ".";
619  OnQuery += m_ColumnsInfos[i].TableForeignKeyDatabase;
620  OnQuery += "=";
621  OnQuery += m_ColumnsInfos[i].TableNameDatabase;
622  OnQuery += ".";
623  OnQuery += m_ColumnsInfos[i].TableKeyDatabase;
624  SelectJoinTables.push_back(OnQuery);
625  }
626  else
627  {
628  if ( m_ColumnsInfos[i].AccessFromTraceTableThroughWhichTable != this->m_CollectionName )
629  {
630  std::cout << "Pb: access table is different than the Collection Table" << std::endl;
631  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
632  std::cout << std::endl;
633  }
634  else
635  {
636  //join the trace table and the collection table (=intermediary
637  // table)
638  SelectJoinTables.push_back(m_ColumnsInfos[i].AccessFromTraceTableThroughWhichTable);
639  std::string OnQuery = this->m_TracesName;
640  OnQuery += ".";
641  OnQuery += this->m_CollectionIDName;
642  OnQuery += "=";
643  OnQuery += this->m_CollectionName;
644  OnQuery += ".";
645  OnQuery += this->m_CollectionIDName;
646  SelectJoinTables.push_back(OnQuery);
647  //join the collection table and the TableNameDatabase of the
648  // ColumnsInfo:
649  SelectJoinTables.push_back(m_ColumnsInfos[i].TableNameDatabase);
650  std::string OnQuerybis = this->m_CollectionName;
651  OnQuerybis += ".";
652  OnQuerybis += m_ColumnsInfos[i].TableForeignKeyDatabase;
653  OnQuerybis += "=";
654  OnQuerybis += m_ColumnsInfos[i].TableNameDatabase;
655  OnQuerybis += ".";
656  OnQuerybis += m_ColumnsInfos[i].TableKeyDatabase;
657  SelectJoinTables.push_back(OnQuerybis);
658  }
659  } //ENDELSE
660  } //ENDIF
661  } //ENDIF
662  i++;
663  } //ENDWHILE
664 
665  return SelectJoinTables;
666 }
667 
668 //--------------------------------------------------------------------------
669 
670 //--------------------------------------------------------------------------
672 {
673  for ( unsigned int i = 0; i < m_RowContainer.size(); i++ )
674  {
675  if ( m_RowContainer[i].first.InfoName == iInfoName )
676  {
677  return i;
678  }
679  }
680  return -1;
681 }
682 
683 //--------------------------------------------------------------------------
684 
685 //--------------------------------------------------------------------------
688  vtkMySQLDatabase *iDatabaseConnector, std::list<unsigned int> iListTPs)
689 {
690  this->ClearRowContainerValues();
691  this->FillRowContainerWithDBValues( iDatabaseConnector,
692  "ImagingsessionID", ConvertToString< unsigned int >(this->m_ImgSessionID),
693  iListTPs);
694  return this->m_RowContainer;
695 }
696 
697 //--------------------------------------------------------------------------
698 
699 //--------------------------------------------------------------------------
702  vtkMySQLDatabase *iDatabaseConnector, int iTraceID)
703 {
704  this->ClearRowContainerValues();
705  this->FillRowContainerWithDBValues( iDatabaseConnector,
706  this->m_TracesIDName, ConvertToString< int >(iTraceID) );
707  return this->m_RowContainer;
708 }
709 
710 //--------------------------------------------------------------------------
711 
712 //--------------------------------------------------------------------------
714  vtkMySQLDatabase *iDatabaseConnector,
715  std::string iRestrictionName, std::string iRestrictionValue,
716  std::list<unsigned int> iListTimePoints)
717 {
718  /*first, get the right parts of the first query:
719  all the fields except the ones where table.field are already in the query:*/
720  std::vector< std::string > JoinFirstTablesOnTraceTable =
722  std::vector< std::string > SelectFirstFields =
724 
725  //Get the right parts of the second query (with only the remaining fields):
726  std::vector< std::string > JoinSecondTablesOnTraceTable =
728  std::vector< std::string > SelectSecondFields =
730 
731  std::vector< std::vector< std::string > > ResultsFirstQuery;
732  std::vector< std::vector< std::string > > ResultsSecondQuery;
733 
734  //then, get the results of the 2 queries:
735  if (iListTimePoints.empty())
736  {
737  ResultsFirstQuery = GetValuesFromSeveralTables(
738  iDatabaseConnector, this->m_TracesName, SelectFirstFields, iRestrictionName,
739  iRestrictionValue, JoinFirstTablesOnTraceTable, true);
740 
741  ResultsSecondQuery = GetValuesFromSeveralTables(
742  iDatabaseConnector, this->m_TracesName, SelectSecondFields, iRestrictionName,
743  iRestrictionValue, JoinSecondTablesOnTraceTable, false);
744  }
745  else
746  {
747  std::vector<FieldWithValue> OrConditions;
748  std::list<unsigned int>::iterator iter = iListTimePoints.begin();
749  while (iter != iListTimePoints.end() )
750  {
751  FieldWithValue temp;
752  temp.Field = "coordinate.TCoord";
753  unsigned int Tp = *iter;
754  temp.Value = ConvertToString<unsigned int>(Tp);
755  OrConditions.push_back(temp);
756  ++iter;
757  }
758  ResultsFirstQuery = GetValuesFromSeveralTables(
759  iDatabaseConnector, this->m_TracesName, SelectFirstFields, iRestrictionName,
760  iRestrictionValue, JoinFirstTablesOnTraceTable, true, OrConditions);
761 
762  ResultsSecondQuery = GetValuesFromSeveralTables(
763  iDatabaseConnector, this->m_TracesName, SelectSecondFields, iRestrictionName,
764  iRestrictionValue, JoinSecondTablesOnTraceTable, false, OrConditions);
765  }
766 
767  //fill the row container with the results of the first query:
768  this->FillRowContainer(ResultsFirstQuery, SelectFirstFields);
769 
770  //fill the row container with the results of the second query:
771  this->FillRowContainer(ResultsSecondQuery, SelectSecondFields);
772 }
773 
774 //--------------------------------------------------------------------------
775 
776 //--------------------------------------------------------------------------
778  std::vector< std::vector< std::string > > *iComputedValues)
779 {
780  std::vector< std::string > ListComputedNames = this->GetNameComputedColumns();
781  if ( !ListComputedNames.empty() )
782  {
783  std::vector< std::vector< std::string > > ComputedValues;
784  if ( iComputedValues == 0 && !ListComputedNames.empty() )
785  {
786  for ( unsigned int j = 0; j < this->GetNumberOfRows(); j++ )
787  {
788  std::vector< std::string > EmptyVector;
789 // int Size = iLinkToRowContainer->GetNumberOfRows();
790  for ( unsigned int i = 0; i < ListComputedNames.size(); i++ )
791  {
792  EmptyVector.push_back("NV");
793  }
794  ComputedValues.push_back(EmptyVector);
795  EmptyVector.clear();
796  }
797  }
798  else
799  {
800  ComputedValues = *iComputedValues;
801  }
802  this->FillRowContainer(
803  ComputedValues, ListComputedNames, "ColumnNameTableWidget");
804  }
805 }
806 
807 //--------------------------------------------------------------------------
808 
809 //--------------------------------------------------------------------------
811  std::string iGroupName)
812 {
813  std::vector< int > oIndexColor;
814  std::string RedInfoName = "RedFor";
815  RedInfoName += iGroupName;
816  oIndexColor.push_back( this->GetIndexInsideRowContainer(RedInfoName) );
817 
818  std::string GreenInfoName = "GreenFor";
819  GreenInfoName += iGroupName;
820  oIndexColor.push_back( this->GetIndexInsideRowContainer(GreenInfoName) );
821 
822  std::string BlueInfoName = "BlueFor";
823  BlueInfoName += iGroupName;
824  oIndexColor.push_back( this->GetIndexInsideRowContainer(BlueInfoName) );
825 
826  std::string AlphaInfoName = "AlphaFor";
827  AlphaInfoName += iGroupName;
828  oIndexColor.push_back( this->GetIndexInsideRowContainer(AlphaInfoName) );
829 
830  return oIndexColor;
831 }
832 
833 //--------------------------------------------------------------------------
834 
835 //--------------------------------------------------------------------------
837 {
838  TWContainerType::iterator iter = this->m_RowContainer.begin();
839 
840  while ( iter != this->m_RowContainer.end() )
841  {
842  iter->second.clear();
843  ++iter;
844  }
845 }
846 
847 //--------------------------------------------------------------------------
848 
849 //--------------------------------------------------------------------------
851 {
852  if ( !this->m_RowContainer.empty() )
853  {
854  //return the number of traceID in the container which correspond to the 2nd
855  // column
856  return this->m_RowContainer.at(1).second.size();
857  }
858  return 0;
859 }
860 
861 //--------------------------------------------------------------------------
862 
863 //--------------------------------------------------------------------------
865 {
866  int IndexColumn = this->GetIndexInsideRowContainer(this->m_TracesIDName);
867 
868  std::vector< std::string > VectorIDsstr = this->m_RowContainer[IndexColumn].second;
869  std::vector< std::string >::iterator iter = VectorIDsstr.begin();
870  std::vector< int > vectorInt;
871  while ( iter != VectorIDsstr.end() )
872  {
873  std::string intstr = *iter;
874  vectorInt.push_back( ss_atoi< int >(intstr) );
875  ++iter;
876  }
877  return vectorInt;
878 }
virtual void SetCommonInfoForTwoTracesTable()=0
Virtual Pure method Fill the vector of GoDBTraceInfoForTableWidget with the info common to 2 traces o...
std::vector< std::vector< std::string > > GetValuesFromSeveralTables(vtkMySQLDatabase *DatabaseConnector, const std::string &MainTable, const std::vector< std::string > &SelectFields, const std::string &field, const std::string &value, const std::vector< std::string > &JoinTablesOnTraceTable, bool Distinct)
std::string m_CollectionName
return a list of all the traces with a bounding box containing the given ZCoord
virtual TWContainerType GetContainerForOneSpecificTrace(vtkMySQLDatabase *iDatabaseConnector, int iTraceID)
get the results of the queries and put them in the row container corresponding to all the data needed...
std::vector< std::string > GetNameComputedColumns()
Return a list with all the ColumnNames for computed values displayed in the tableWidget.
std::list< std::pair< std::string, std::string > > GetListColumnsNamesAndToolTipsForTableWidget()
Return a list with all the ColumnNames and tooltips to be displayed in the tableWidget.
std::vector< std::pair< GoDBTraceInfoForTableWidget, std::vector< std::string > > > TWContainerType
std::vector< int > GetAllTraceIDsInContainer()
return all the traces IDs present in the RowContainer
std::vector< std::string > GetQueryStringForTraceJoinedTables(bool SameFieldsInQuery)
return a vector of string with the tables to be joined with the trace table in the database query for...
structure to pass the column information between the Table Widget and the Database ...
virtual std::vector< GoDBTraceInfoForTableWidget > GetColumnsInfoForTraceTable()
Fill a vector of GoDBTraceInfoForTableWidget with the info needed to fill the table widget for all th...
std::vector< int > GetIndexForGroupColor(std::string iGroupName)
get the results of the queries and put them in the row container corresponding to all the data needed...
void FillRowContainerForComputedValues(std::vector< std::vector< std::string > > *iComputedValues)
fill the row container with the values calculated and stored in th meshAttributes ...
void FillRowContainer(std::vector< std::vector< std::string > > iResultsFromQuery, std::vector< std::string > iSelectFields, std::string BaseOn="")
fill the columns of the row container following the vector of string containing the columns to be fil...
std::vector< GoDBTraceInfoForTableWidget > m_ColumnsInfos
int GetIndexInsideRowContainer(std::string iInfoName)
return the index in the row container for the column with the given InfoName
GoDBTableWidgetContainer()
Default Constructor.
std::vector< std::string > GetQueryStringForSelectFieldsTables(bool SameFieldsInQuery)
return a vector of the table.fields to be selected from the database for all the fields except the on...
virtual TWContainerType GetContainerLoadedWithAllFromDB(vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTPs=std::list< unsigned int >())
get the results of the queries and put them in the row container corresponding to all the data needed...
virtual void FillRowContainerWithDBValues(vtkMySQLDatabase *iDatabaseConnector, std::string iRestrictionName, std::string iRestrictionValue, std::list< unsigned int > iListTimepoints=std::list< unsigned int >())