15 QVector< US_Rotor::Lab >& labList,
US_DB2* db )
17 QStringList q(
"get_lab_names" );
22 labIDs << db->
value( 0 ).toString();
24 if ( labIDs.size() == 0 )
29 for (
int i = 0; i < labIDs.size(); i++ )
33 lab.
readDB( labIDs[ i ].toInt(), db );
34 labList.push_back( lab );
51 QString filename = path +
"/labs.xml";
53 QFile file( filename );
54 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text) )
56 qDebug() <<
"Error: can't open file for writing"
63 xml.setDevice( &file );
64 xml.setAutoFormatting(
true );
66 xml.writeStartDocument();
67 xml.writeDTD(
"<!DOCTYPE US_Lab>");
68 xml.writeStartElement(
"LabData");
69 xml.writeAttribute(
"version",
"1.0");
72 for (
int i = 0; i < labList.size(); i++ )
76 xml.writeStartElement(
"lab" );
77 xml.writeAttribute (
"id", QString::number( lab.
ID ) );
78 xml.writeAttribute (
"guid", lab.
GUID );
79 xml.writeAttribute (
"name", lab.
name );
80 xml.writeAttribute (
"building", lab.
building );
81 xml.writeAttribute (
"room", lab.
room );
85 xml.writeStartElement(
"instrument" );
86 xml.writeAttribute (
"id", QString::number( instrument.
ID ) );
87 xml.writeAttribute (
"name", instrument.
name );
88 xml.writeAttribute (
"serial", instrument.
serial );
92 xml.writeStartElement(
"operator" );
93 xml.writeAttribute (
"id", QString::number( oper.
ID ) );
94 xml.writeAttribute (
"guid", oper.
GUID );
95 xml.writeAttribute (
"lname", oper.
lname );
96 xml.writeAttribute (
"fname", oper.
fname );
97 xml.writeEndElement ();
100 xml.writeEndElement ();
103 xml.writeEndElement ();
106 xml.writeEndElement ();
107 xml.writeEndDocument ();
121 QFile file( labFilename );
123 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text ) )
127 QFile::copy( defaultFilename, labFilename );
129 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
131 qDebug() <<
"Error: Could not read lab file\n"
139 QXmlStreamReader xml( &file );
141 while ( ! xml.atEnd() )
145 if ( xml.isStartElement() )
147 if ( xml.name() ==
"lab" )
151 QXmlStreamAttributes a = xml.attributes();
152 lab.
ID = a.value(
"id" ).toString().toInt();
153 lab.
GUID = a.value(
"guid" ).toString();
154 lab.
name = a.value(
"name" ).toString();
155 lab.
building = a.value(
"building" ).toString();
156 lab.
room = a.value(
"room" ).toString();
159 labList.push_back( lab );
166 if ( xml.hasError() )
168 qDebug() <<
"Error: xml error: \n"
169 << xml.errorString();
178 while ( ! xml.atEnd() )
182 if ( xml.isEndElement() && xml.name() ==
"lab" )
return;
184 if ( xml.isStartElement() )
186 if ( xml.name() ==
"instrument" )
190 QXmlStreamAttributes a = xml.attributes();
191 instrument.
ID = a.value(
"id" ).toString().toInt();
192 instrument.
name = a.value(
"name" ).toString();
193 instrument.
serial = a.value(
"serial" ).toString();
204 while ( ! xml.atEnd() )
208 if ( xml.isEndElement() && xml.name() ==
"instrument" )
return;
210 if ( xml.isStartElement() )
212 if ( xml.name() ==
"operator" )
216 QXmlStreamAttributes a = xml.attributes();
217 oper.
ID = a.value(
"id" ).toString().toInt();
218 oper.
GUID = a.value(
"guid" ).toString();
219 oper.
lname = a.value(
"lname" ).toString();
220 oper.
fname = a.value(
"fname" ).toString();
230 QVector< US_Rotor::AbstractRotor >& arList,
US_DB2* db )
232 QStringList q(
"get_abstractRotor_names" );
237 arIDs << db->
value( 0 ).toString();
239 if ( arIDs.size() == 0 )
244 for (
int i = 0; i < arIDs.size(); i++ )
248 ar.
readDB( arIDs[ i ].toInt(), db );
249 arList.push_back( ar );
259 QFile file( filename );
263 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
265 qDebug() <<
"Error: Could not read abstract rotor file\n"
270 QXmlStreamReader xml( &file );
272 while ( ! xml.atEnd() )
276 if ( xml.isStartElement() )
278 if ( xml.name() ==
"abstractRotor" )
282 QXmlStreamAttributes a = xml.attributes();
283 ar.
ID = a.value(
"id" ).toString().toInt();
284 ar.
GUID = a.value(
"guid" ).toString();
285 ar.
name = a.value(
"name" ).toString();
286 ar.
material = a.value(
"materialName" ).toString();
287 ar.
numHoles = a.value(
"numHoles" ).toString().toInt();
288 ar.
maxRPM = a.value(
"maxRPM" ).toString().toInt();
289 ar.
magnetOffset = a.value(
"magnetOffset" ).toString().toFloat();
290 ar.
cellCenter = a.value(
"cellCenter" ).toString().toFloat();
293 arList.push_back( ar );
300 if ( xml.hasError() )
302 qDebug() <<
"Error: xml error: \n"
303 << xml.errorString();
312 QVector< US_Rotor::Rotor >& rotors,
int labID )
321 QStringList filter(
"R*.xml" );
322 QStringList names = dir.entryList( filter, QDir::Files, QDir::Name );
324 for (
int i = 0; i < names.size(); i++ )
326 QFile file( path +
"/" + names[ i ] );
328 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
330 qDebug() <<
"Error: Could not read rotor file\n"
335 QXmlStreamReader xml( &file );
337 while ( ! xml.atEnd() )
341 if ( xml.isStartElement() )
343 if ( xml.name() ==
"Rotor" )
346 QXmlStreamAttributes a = xml.attributes();
348 r.
ID = a.value(
"id" ).toString().toInt();
349 r.
GUID = a.value(
"guid" ).toString();
352 r.
labID = a.value(
"labID" ).toString().toInt();
353 r.
name = a.value(
"name" ).toString();
356 if ( r.
labID == labID )
357 rotors.push_back( r );
365 if ( xml.hasError() )
367 qDebug() <<
"Error: xml error: \n"
368 << xml.errorString();
373 if ( rotors.size() == 0 )
381 QVector< US_Rotor::RotorCalibration >& profiles,
int rotorID )
390 QStringList filter(
"C*.xml" );
391 QStringList names = dir.entryList( filter, QDir::Files, QDir::Name );
393 for (
int i = 0; i < names.size(); i++ )
395 QFile file( path +
"/" + names[ i ] );
397 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
399 qDebug() <<
"Error: Could not read rotor calibration file\n"
404 QXmlStreamReader xml( &file );
407 while ( ! xml.atEnd() )
411 if ( xml.isStartElement() )
413 if ( xml.name() ==
"Calibration" )
415 QXmlStreamAttributes a = xml.attributes();
417 rc.
ID = a.value(
"id" ).toString().toInt();
418 rc.
GUID = a.value(
"guid" ).toString();
419 rc.
rotorID = a.value(
"rotorID" ).toString().toInt();
420 rc.
rotorGUID = a.value(
"rotorGUID" ).toString();
423 rc.
coeff1 = a.value(
"coeff1" ).toString().toFloat();
424 rc.
coeff2 = a.value(
"coeff2" ).toString().toFloat();
425 rc.
label = a.value(
"label" ).toString();
426 rc.
report = QString(
"" );
427 rc.
lastUpdated = QDate::fromString( a.value(
"lastUpdated" ).toString(),
"yyyy-MM-dd" );
428 rc.
omega2t = a.value(
"omega2t" ).toString().toFloat();
437 if ( xml.hasError() )
439 qDebug() <<
"Error: xml error: \n"
440 << xml.errorString();
444 profiles.push_back( rc );
447 if ( profiles.size() == 0 )
455 const QString& lookupTag,
463 qDebug() <<
"Error: could not create the directory";
468 QStringList filter( fileMask );
469 QStringList names = dir.entryList( filter, QDir::Files, QDir::Name );
472 for (
int i = 0; i < names.size(); i++ )
474 filename = path +
"/" + names[ i ];
475 QFile file( filename );
477 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
479 QXmlStreamReader xml( &file );
480 while ( ! xml.atEnd() )
484 if ( xml.isStartElement() )
486 if ( xml.name() == lookupTag )
488 QXmlStreamAttributes a = xml.attributes();
490 if ( a.value(
"id" ).toString().toInt() == lookupID ) found =
true;
502 filename = QString(
"" );
515 if ( ! dir.exists( path ) )
517 if ( ! dir.mkpath( path ) )
519 qDebug() <<
"Error: Could not create default directory for rotors\n"
526 QDir etcDir ( defaultDir );
527 QStringList files = etcDir.entryList( QDir::NoDotAndDotDot | QDir::Files );
529 foreach( QString file, files )
530 QFile::copy( defaultDir +
"/" + file, path +
"/" + file );
538 const QString& path,
const QString& fileMask,
539 const QString& lookupTag,
const int& lookupID,
bool& newFile )
542 QStringList filter( fileMask );
543 QStringList f_names = f.entryList( filter, QDir::Files, QDir::Name );
547 for (
int i = 0; i < f_names.size(); i++ )
549 QFile b_file( path +
"/" + f_names[ i ] );
551 if ( ! b_file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
553 QXmlStreamReader xml( &b_file );
555 while ( ! xml.atEnd() )
559 if ( xml.isStartElement() )
561 if ( xml.name() == lookupTag )
563 QXmlStreamAttributes a = xml.attributes();
565 if ( a.value(
"id" ).toString().toInt() == lookupID )
568 filename = path +
"/" + f_names[ i ];
577 if ( ! newFile )
return filename;
581 int number = ( f_names.size() > 0 ) ? f_names.last().mid( 1, 7 ).toInt() : 0;
583 QString startName =
"/" + fileMask.left( 1 );
584 return path + startName + QString().sprintf(
"%07i", number + 1 ) +
".xml";
596 QStringList q(
"get_lab_info" );
597 q << QString::number( labID );
609 GUID = db->
value( 0 ).toString();
610 name = db->
value( 1 ).toString();
611 building = db->
value( 2 ).toString();
612 room = db->
value( 3 ).toString();
617 q << QString(
"get_instrument_names" )
618 << QString::number( labID );
624 QList< int > instrumentIDs;
629 int ID = db->
value( 0 ).toString().toInt();
634 foreach (
int ID, instrumentIDs )
639 q << QString(
"get_instrument_info" )
640 << QString::number( ID );
645 instrument.
name = db->
value( 0 ).toString();
649 this->instruments << instrument;
653 for (
int i = 0; i < instruments.size(); i++ )
656 q << QString(
"get_operator_names" )
657 << QString::number( instruments[ i ].ID );
666 oper.
ID = db->
value( 0 ).toString().toInt();
671 this->instruments[ i ].operators << oper;
692 qDebug() <<
"ID = " << ID ;
693 qDebug() <<
"GUID = " << GUID ;
694 qDebug() <<
"name = " << name ;
695 qDebug() <<
"building = " << building ;
696 qDebug() <<
"room = " << room ;
698 qDebug() <<
"Instruments...";
701 qDebug() <<
" instrument ID = " << instrument.
ID ;
702 qDebug() <<
" instrument name = " << instrument.
name ;
703 qDebug() <<
" instrument serial = " << instrument.
serial ;
705 qDebug() <<
" Operators...";
708 qDebug() <<
" operator ID = " << oper.
ID ;
709 qDebug() <<
" operator GUID = " << oper.
GUID ;
710 qDebug() <<
" operator lname = " << oper.
lname ;
711 qDebug() <<
" operator fname = " << oper.
fname ;
725 QStringList q(
"get_abstractRotor_info" );
726 q << QString::number( abstractRotorID );
737 this->ID = abstractRotorID;
738 GUID = db->
value(0).toString();
739 name = db->
value(1).toString();
740 material = db->
value(2).toString();
741 numHoles = db->
value(3).toInt();
742 maxRPM = db->
value(4).toInt();
743 magnetOffset = db->
value(5).toFloat();
744 cellCenter = db->
value(6).toFloat();
745 manufacturer = db->
value(7).toString();
765 qDebug() <<
"ID = " << ID ;
766 qDebug() <<
"GUID = " << GUID ;
767 qDebug() <<
"name = " << name ;
768 qDebug() <<
"material = " << material ;
769 qDebug() <<
"numHoles = " << numHoles ;
770 qDebug() <<
"maxRPM = " << maxRPM ;
771 qDebug() <<
"magnetOffset = " << magnetOffset ;
772 qDebug() <<
"cellCenter = " << cellCenter ;
773 qDebug() <<
"manufacturer = " << manufacturer ;
784 QStringList q(
"add_rotor" );
785 q << QString::number( abstractRotorID )
787 << QString::number(
labID )
801 QStringList q(
"get_rotor_info" );
802 q << QString::number( rotorID );
814 abstractRotorID = db->
value( 4 ).toString().toInt();
815 abstractRotorGUID = db->
value( 5 ).toString();
817 GUID = db->
value( 0 ).toString();
818 name = db->
value( 1 ).toString();
819 serialNumber = db->
value( 2 ).toString();
827 QStringList q(
"delete_rotor" );
828 q << QString::number( rotorID );
840 QRegExp rx(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" );
842 if ( ! rx.exactMatch( GUID ) )
857 QFile file( filename );
858 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text) )
860 qDebug() <<
"Error: can't open file for writing"
866 QXmlStreamWriter xml;
867 xml.setDevice( &file );
868 xml.setAutoFormatting(
true );
870 xml.writeStartDocument();
871 xml.writeDTD(
"<!DOCTYPE US_Rotor>");
872 xml.writeStartElement(
"RotorData");
873 xml.writeAttribute(
"version",
"1.0");
875 xml.writeStartElement(
"Rotor" );
876 xml.writeAttribute (
"id", QString::number( ID ) );
877 xml.writeAttribute (
"guid", GUID );
878 xml.writeAttribute (
"abstractRotorID", QString::number( abstractRotorID ) );
879 xml.writeAttribute (
"abstractRotorGUID", abstractRotorGUID );
880 xml.writeAttribute (
"labID", QString::number(
labID ) );
881 xml.writeAttribute (
"name", name );
882 xml.writeAttribute (
"serialNumber", serialNumber );
883 xml.writeEndElement ();
885 xml.writeEndElement ();
886 xml.writeEndDocument ();
895 bool found =
diskFilename(
"R*.xml",
"Rotor",
id, filename );
899 qDebug() <<
"Error: file not found for id "
904 QFile file( filename );
905 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text) )
907 qDebug() <<
"Error: can't open file for reading"
913 QXmlStreamReader xml( &file );
917 while ( ! xml.atEnd() )
921 if ( xml.isStartElement() )
923 if ( xml.name() ==
"Rotor" )
925 QXmlStreamAttributes a = xml.attributes();
927 ID = a.value(
"id" ).toString().toInt();
928 GUID = a.value(
"guid" ).toString();
929 abstractRotorID = a.value(
"abstractRotorID" ).toString().toInt();
930 abstractRotorGUID = a.value(
"abstractRotorGUID" ).toString();
931 labID = a.value(
"labID" ).toString().toInt();
932 name = a.value(
"name" ).toString();
933 serialNumber = a.value(
"serialNumber" ).toString();
941 if ( xml.hasError() )
943 qDebug() <<
"Error: xml error: \n"
944 << xml.errorString();
954 abstractRotorID = -1;
957 name =
"< Not Selected >";
958 serialNumber =
"< Not Selected >";
963 qDebug() <<
"ID = " << ID ;
964 qDebug() <<
"abstractRotorID = " << abstractRotorID ;
965 qDebug() <<
"labID = " <<
labID ;
966 qDebug() <<
"GUID = " << GUID ;
967 qDebug() <<
"name = " << name ;
968 qDebug() <<
"serialNumber = " << serialNumber ;
978 QStringList q(
"add_rotor_calibration" );
979 q << QString::number( rotorID )
982 << QString::number( coeff1 )
983 << QString::number( coeff2 )
984 << QString::number( omega2t )
985 << QString::number( calibrationExperimentID )
1000 QStringList q(
"get_rotor_calibration_info" );
1001 q << QString::number( calibrationID );
1012 this->ID = calibrationID;
1013 this->GUID = db->
value( 0 ).toString();
1014 this->rotorID = db->
value( 1 ).toString().toInt();
1015 this->rotorGUID = db->
value( 2 ).toString();
1016 this->calibrationExperimentID = db->
value( 8 ).toString().toInt();
1018 this->coeff1 = db->
value( 4 ).toString().toFloat();
1019 this->coeff2 = db->
value( 5 ).toString().toFloat();
1020 this->label = db->
value( 9 ).toString();
1021 this->report = db->
value( 3 ).toString();
1023 QStringList dateParts = db->
value( 7 ).toString().split(
" " );
1024 this->lastUpdated = QDate::fromString( dateParts[ 0 ],
"yyyy-MM-dd" );
1026 this->omega2t = db->
value( 6 ).toString().toFloat();
1035 QStringList q(
"delete_rotor_calibration" );
1036 q << QString::number( calibrationID );
1048 QStringList calibrationIDs;
1050 QStringList q(
"get_rotor_calibration_profiles" );
1051 q << QString::number( rotorID );
1055 while ( db->
next() )
1056 calibrationIDs << db->
value( 0 ).toString();
1059 int ndx = calibrationIDs.indexOf( QString::number( this->ID ) );
1060 calibrationIDs.removeAt( ndx );
1063 if ( calibrationIDs.isEmpty() )
1066 oldCalibrationID = -1;
1067 foreach ( QString calibrationID, calibrationIDs )
1070 q <<
"get_rotor_calibration_info"
1075 QString report = db->
value( 3 ).toString();
1076 QString label = db->
value( 9 ).toString();
1078 if ( report.contains(
"This is a dummy calibration --- please replace." ) &&
1079 label.contains(
"Dummy Calibration" ) )
1081 oldCalibrationID = calibrationID.toInt();
1087 if ( oldCalibrationID == -1 )
1092 q <<
"replace_rotor_calibration"
1093 << QString::number( oldCalibrationID )
1094 << QString::number( this->ID );
1104 QRegExp rx(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" );
1106 if ( ! rx.exactMatch( GUID ) )
1121 QFile file( filename );
1122 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text) )
1124 qDebug() <<
"Error: can't open file for writing"
1130 QXmlStreamWriter xml;
1131 xml.setDevice( &file );
1132 xml.setAutoFormatting(
true );
1134 xml.writeStartDocument();
1135 xml.writeDTD(
"<!DOCTYPE US_RotorCalibration>");
1136 xml.writeStartElement(
"RotorCalibrationData");
1137 xml.writeAttribute(
"version",
"1.0");
1139 xml.writeStartElement(
"Calibration" );
1140 xml.writeAttribute (
"id", QString::number( ID ) );
1141 xml.writeAttribute (
"guid", GUID );
1142 xml.writeAttribute (
"rotorID", QString::number( rotorID ) );
1143 xml.writeAttribute (
"rotorGUID", rotorGUID );
1144 xml.writeAttribute (
"calExpID", QString::number( calibrationExperimentID ) );
1145 xml.writeAttribute (
"calExpGUID", calibrationExperimentGUID );
1146 xml.writeAttribute (
"coeff1", QString::number( coeff1 ) );
1147 xml.writeAttribute (
"coeff2", QString::number( coeff2 ) );
1148 xml.writeAttribute (
"lastUpdated", lastUpdated.toString(
"yyyy-MM-dd" ) );
1149 xml.writeAttribute (
"omega2t", QString::number( omega2t ) );
1150 xml.writeAttribute (
"label", label );
1151 xml.writeTextElement (
"report", report );
1152 xml.writeEndElement ();
1154 xml.writeEndElement ();
1155 xml.writeEndDocument ();
1164 bool found =
diskFilename(
"C*.xml",
"Calibration",
id, filename );
1168 qDebug() <<
"Error: file not found for id "
1173 QFile file( filename );
1174 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text) )
1176 qDebug() <<
"Error: can't open file for reading"
1182 QXmlStreamReader xml( &file );
1186 while ( ! xml.atEnd() )
1190 if ( xml.isStartElement() )
1192 if ( xml.name() ==
"Calibration" )
1194 QXmlStreamAttributes a = xml.attributes();
1196 ID = a.value(
"id" ).toString().toInt();
1197 GUID = a.value(
"guid" ).toString();
1198 rotorID = a.value(
"rotorID" ).toString().toInt();
1199 rotorGUID = a.value(
"rotorGUID" ).toString();
1200 calibrationExperimentID = a.value(
"calExpID" ).toString().toInt();
1201 calibrationExperimentGUID = a.value(
"calExpGUID" ).toString();
1202 coeff1 = a.value(
"coeff1" ).toString().toFloat();
1203 coeff2 = a.value(
"coeff2" ).toString().toFloat();
1204 lastUpdated = QDate::fromString( a.value(
"lastUpdated" ).toString(),
"yyyy-MM-dd" );
1205 omega2t = a.value(
"omega2t" ).toString().toFloat();
1206 label = a.value(
"label" ).toString();
1215 if ( xml.hasError() )
1217 qDebug() <<
"Error: xml error: \n"
1218 << xml.errorString();
1227 while ( !xml.atEnd() )
1231 if ( xml.isEndElement() && xml.name() ==
"Calibration" )
return;
1233 if ( xml.isStartElement() )
1235 if ( xml.name() ==
"report" )
1238 report = xml.text().toString();
1248 calibrationExperimentGUID =
"";
1253 lastUpdated = QDate::currentDate();
1259 qDebug() <<
"GUID = " << GUID;
1260 qDebug() <<
"rotorID = " << rotorID;
1261 qDebug() <<
"rotorGUID = " << rotorGUID;
1262 qDebug() <<
"calibration experiment ID = " << calibrationExperimentID;
1263 qDebug() <<
"calibration experiment GUID = " << calibrationExperimentGUID;
1264 qDebug() <<
"coeff1 = " << coeff1;
1265 qDebug() <<
"coeff2 = " << coeff2;
1266 qDebug() <<
"last updated = " << lastUpdated.toString(
"yyyy-MM-dd" );
1267 qDebug() <<
"omega2t = " << QString::number( omega2t );
1268 qDebug() <<
"label = " << label;
1269 qDebug() <<
"report";