GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBTraceRow.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 =========================================================================*/
34 #include "GoDBTraceRow.h"
35 #include "GoDBColorRow.h"
37 #include "GoDBRecordSetHelper.h"
39 #include "vtkSmartPointer.h"
40 
42 {
43  this->InitializeMap();
44 }
45 
46 //-------------------------------------------------------------------------
47 
48 //-------------------------------------------------------------------------
49 GoDBTraceRow::GoDBTraceRow(vtkMySQLDatabase *DatabaseConnector, vtkPolyData *TraceVisu,
51  unsigned int ImgSessionID)
52 {
53  (void)Min;
54  (void)Max;
55  (void)TraceVisu;
56  (void)DatabaseConnector;
57 
58  this->InitializeMap();
59  this->m_MapRow["ImagingSessionID"] =
60  ConvertToString< unsigned int >(ImgSessionID);
61 }
62 
63 //-------------------------------------------------------------------------
64 
65 //-------------------------------------------------------------------------
66 /*GoDBTraceRow::GoDBTraceRow(vtkMySQLDatabase *DatabaseConnector,
67  std::string TraceVisu, GoDBCoordinateRow Min, GoDBCoordinateRow Max,
68  unsigned int ImgSessionID)
69 {
70 
71  this->InitializeMap();
72  this->SetTheBoundingBox(DatabaseConnector, Min, Max);
73  this->m_MapRow["ImagingSessionID"] =
74  ConvertToString< unsigned int >(ImgSessionID);
75 
76  this->SetField("Points", TraceVisu);
77 }*/
78 //-------------------------------------------------------------------------
79 
80 //-------------------------------------------------------------------------
82 {
83  this->m_MapRow["ImagingSessionID"] = std::string( "0" );//ConvertToString< int >(0);
84  this->m_MapRow["ColorID"] = std::string( "1" );//ConvertToString< int >(1);
85  this->m_MapRow["CoordIDMax"] = std::string( "0" );//ConvertToString< int >(0);
86  this->m_MapRow["CoordIDMin"] = std::string( "0" );//ConvertToString< int >(0);
87  this->m_MapRow["Points"] = std::string( "0" );//ConvertToString< int >(0);
88 }
89 
90 //-------------------------------------------------------------------------
91 
92 //-------------------------------------------------------------------------
93 void GoDBTraceRow::SetTheBoundingBox(vtkMySQLDatabase *DatabaseConnector,
95 {
96  int CoordMin = Min.DoesThisCoordinateExist(DatabaseConnector);
97 
98  if ( CoordMin == -1 )
99  {
100  CoordMin = Min.SaveInDB(DatabaseConnector);
101  }
102  this->m_MapRow["CoordIDMin"] = ConvertToString< int >(CoordMin);
103 
104  int CoordMax = Max.DoesThisCoordinateExist(DatabaseConnector);
105  if ( CoordMax == -1 )
106  {
107  CoordMax = Max.SaveInDB(DatabaseConnector);
108  }
109  this->m_MapRow["CoordIDMax"] = ConvertToString< int >(CoordMax);
110 }
111 
112 //-------------------------------------------------------------------------
113 
114 //-------------------------------------------------------------------------
116  vtkMySQLDatabase *DatabaseConnector)
117 {
118  std::vector< FieldWithValue > Conditions;
119  this->AddConditions("CoordIDMax", Conditions);
120  this->AddConditions("CoordIDMin", Conditions);
121  this->AddConditions("ImagingSessionID", Conditions);
122 
123  return FindOneID(DatabaseConnector, this->m_TableName, this->m_TableIDName, Conditions);
124 }
125 
126 //-------------------------------------------------------------------------
127 
128 //-------------------------------------------------------------------------
129 void GoDBTraceRow::SetColor(unsigned int Red, unsigned int Green,
130  unsigned int Blue, unsigned int Alpha, std::string ColorName,
131  vtkMySQLDatabase *DatabaseConnector)
132 {
133  GoDBColorRow ColorRow;
134 
135  ColorRow.SetField< int >("Red", Red);
136  ColorRow.SetField< int >("Green", Green);
137  ColorRow.SetField< int >("Blue", Blue);
138  ColorRow.SetField< int >("Alpha", Alpha);
139  ColorRow.SetField("Name", ColorName);
140  int ColorID = ColorRow.DoesThisEntityAlreadyExists(DatabaseConnector);
141  if ( ColorID == -1 )
142  {
143  this->m_MapRow["ColorID"] = ConvertToString< int >( ColorRow.SaveInDB(DatabaseConnector) );
144  }
145  else
146  {
147  this->SetField< int >("ColorID", ColorID);
148  }
149 }
150 
151 //-------------------------------------------------------------------------
152 
153 //-------------------------------------------------------------------------
155 {
156  return this->m_CollectionIDName;
157 }
158 
159 //-------------------------------------------------------------------------
160 
161 //-------------------------------------------------------------------------
163 {
164  return this->m_CollectionName;
165 }
166 
167 //-------------------------------------------------------------------------
168 
169 //-------------------------------------------------------------------------
170 void GoDBTraceRow::SetCollectionID(unsigned int iCollectionID)
171 {
172  this->SetField< int >(this->m_CollectionIDName, iCollectionID);
173 }
174 
175 //-------------------------------------------------------------------------
176 
177 //-------------------------------------------------------------------------
178 void GoDBTraceRow::SetImgSessionID(unsigned int iImgSessionID)
179 {
180  this->SetField< int >("ImagingSessionID", iImgSessionID);
181 }
182 
183 //-------------------------------------------------------------------------
184 
185 //-------------------------------------------------------------------------
186 bool GoDBTraceRow::SetValuesForSpecificID(int ID, vtkMySQLDatabase *iDatabaseConnector)
187 {
188  if ( GoDBRow::SetValuesForSpecificID(ID, iDatabaseConnector) )
189  {
190  //add the "" for the string
191  this->SetField("Points", this->m_MapRow["Points"]);
192  return true;
193  }
194  return false;
195 }