00001 #include "glimsglobals.h" 00002 #include <iostream> 00003 00004 std::vector<QColor> GLIMSGlobals::AVAILCOLORS; 00005 std::vector<std::string> GLIMSGlobals::AVAILCOLORSTR; 00006 00007 bool GLIMSGlobals::mGlbsLoaded = false; 00008 00009 // LINE ATTRIBUTES 00010 std::vector<Attr> GLIMSGlobals::mGlbGlacTypes; 00011 std::vector<Attr> GLIMSGlobals::mGlbMDF; 00012 std::vector<Attr> GLIMSGlobals::mGlbTypes; 00013 std::vector<Attr> GLIMSGlobals::mGlbFtrs; 00014 std::vector<Attr> GLIMSGlobals::mGlbLbls; 00015 00016 // GLACIER ATTRIBUTES 00017 std::vector<Attr> GLIMSGlobals::mGlbPrimCsfn; 00018 std::vector<Attr> GLIMSGlobals::mGlbForm; 00019 std::vector<Attr> GLIMSGlobals::mGlbFrntChar; 00020 std::vector<Attr> GLIMSGlobals::mGlbLonChar; 00021 std::vector<Attr> GLIMSGlobals::mGlbDomMassSrc; 00022 std::vector<Attr> GLIMSGlobals::mGlbTongueAct; 00023 00024 const std::string GLIMSGlobals::GFTR_FILE = "globals/lineftrs.atr"; 00025 const std::string GLIMSGlobals::GLBL_FILE = "globals/linelbls.atr"; 00026 const std::string GLIMSGlobals::GLDF_FILE = "globals/global.ldf"; 00027 const std::string GLIMSGlobals::GMDF_FILE = "globals/linemat.atr"; 00028 const std::string GLIMSGlobals::GTYPE_FILE = "globals/linetypes.atr"; 00029 const std::string GLIMSGlobals::GCAT_FILE = "globals/linecatagory.atr"; 00030 const std::string GLIMSGlobals::GPCLASS_FILE = "globals/glacpclass.atr"; 00031 const std::string GLIMSGlobals::GFORM_FILE = "globals/glacform.atr"; 00032 const std::string GLIMSGlobals::GFCHAR_FILE = "globals/glacfrontalchar.atr"; 00033 const std::string GLIMSGlobals::GLCHAR_FILE = "globals/glaclonchar.atr"; 00034 const std::string GLIMSGlobals::GDOMMS_FILE = "globals/glacdommass.atr"; 00035 const std::string GLIMSGlobals::GTGACT_FILE = "globals/glactongueact.atr"; 00036 00037 LineDefSet GLIMSGlobals::mGlbLDFSet; 00038 00039 void GLIMSGlobals::loadGlobals( ) { 00040 if ( mGlbsLoaded ) 00041 return; 00042 mGlbsLoaded = true; 00043 00044 // LOAD GLOBALS 00045 readAttrFile( mGlbMDF, GMDF_FILE ); 00046 readAttrFile( mGlbTypes, GTYPE_FILE ); 00047 readAttrFile( mGlbLbls, GLBL_FILE ); 00048 readAttrFile( mGlbFtrs, GFTR_FILE ); 00049 readAttrFile( mGlbGlacTypes, GCAT_FILE ); 00050 00051 // LOAD GLOBAL GLACIER ATTRIBUTES 00052 readAttrFile( mGlbPrimCsfn, GPCLASS_FILE ); 00053 readAttrFile( mGlbForm, GFORM_FILE ); 00054 readAttrFile( mGlbFrntChar, GFCHAR_FILE ); 00055 readAttrFile( mGlbLonChar, GLCHAR_FILE ); 00056 readAttrFile( mGlbDomMassSrc, GDOMMS_FILE ); 00057 readAttrFile( mGlbTongueAct, GTGACT_FILE ); 00058 00059 mGlbLDFSet.fromXMLFile( GLDF_FILE, "LineDefinitions" ); 00060 // INITIALIZE AVAILCOLORS 00061 AVAILCOLORS.push_back( QColor(0,0,255) ); 00062 AVAILCOLORS.push_back( QColor(255,0,0) ); 00063 AVAILCOLORS.push_back( QColor(0,255,0) ); 00064 AVAILCOLORS.push_back( QColor(255,0,255) ); 00065 AVAILCOLORS.push_back( QColor(255,255,0) ); 00066 AVAILCOLORS.push_back( QColor(255,216,0) ); 00067 AVAILCOLORS.push_back( QColor(215,115,70) ); 00068 AVAILCOLORS.push_back( QColor(0,255,255) ); 00069 AVAILCOLORS.push_back( QColor(0,0,0) ); 00070 AVAILCOLORS.push_back( QColor(255,255,255) ); 00071 00072 AVAILCOLORSTR.push_back( "Blue" ); 00073 AVAILCOLORSTR.push_back( "Red" ); 00074 AVAILCOLORSTR.push_back( "Green" ); 00075 AVAILCOLORSTR.push_back( "Purple" ); 00076 AVAILCOLORSTR.push_back( "Yellow" ); 00077 AVAILCOLORSTR.push_back( "Gold" ); 00078 AVAILCOLORSTR.push_back( "Orange" ); 00079 AVAILCOLORSTR.push_back( "Cyan" ); 00080 AVAILCOLORSTR.push_back( "Black" ); 00081 AVAILCOLORSTR.push_back( "White" ); 00082 } 00083 00084 void GLIMSGlobals::readAttrFile( std::vector<Attr> &vec, 00085 std::string fname ) { 00086 QDomElement e; 00087 QDomDocument doc; 00088 QFile f( fname.c_str() ); 00089 if ( !f.open( IO_ReadOnly ) ) 00090 return; 00091 if ( !doc.setContent( &f ) ) { 00092 f.close(); 00093 return; 00094 } 00095 f.close(); 00096 00097 e = doc.documentElement(); 00098 QDomNode node = e.firstChild(); 00099 while ( !node.isNull() ) { 00100 if ( !node.isElement() ) 00101 break; 00102 e = node.toElement(); 00103 Attr attr; 00104 attr.fromXML( e ); 00105 vec.push_back( attr ); 00106 node = node.nextSibling(); 00107 } 00108 } 00109 00110 00111 std::string GLIMSGlobals::getIDOf (const std::vector<Attr> glacierAttribute, const std::string attributeValue) { 00112 for ( unsigned int i = 0 ; i < glacierAttribute.size() ; i++ ) { 00113 if ( attributeValue == glacierAttribute[i].value ) { 00114 return glacierAttribute[i].id ; 00115 } 00116 } 00117 return "" ; 00118 } 00119 00120 int GLIMSGlobals::getIntIDOf (const std::vector<Attr> glacierAttribute, const std::string attributeValue) { 00121 // get the ID of an attribute with value attributeValue 00122 std::string attIDstr = getIDOf (glacierAttribute, attributeValue) ; 00123 if ( attIDstr.length() == 0 || attIDstr == "-999" /* nul */ ) { 00124 return -1 ; 00125 } 00126 00127 // put the ID in a stringstream so it can be manipulated 00128 std::stringstream attIDstrstream ; 00129 attIDstrstream << attIDstr ; 00130 00131 // read the ID out of the stringstream into an integer and return 00132 int attIDint = 0 ; 00133 attIDstrstream >> attIDint ; 00134 return attIDint ; 00135 } 00136 00137 // get the index where this value is stored in the vector 00138 int GLIMSGlobals::getNdxOfValue (const std::vector<Attr> glacierAttribute, const std::string attributeValue) { 00139 unsigned int index = 0 ; 00140 for ( ; index < glacierAttribute.size() ; index++ ) { 00141 if ( attributeValue == glacierAttribute[index].value ) { 00142 return index ; 00143 } 00144 } 00145 return 0 ; 00146 } 00147 00148 int GLIMSGlobals::getNdxOfID (const std::vector<Attr> glacierAttribute, const int attributeID) { 00149 std::stringstream attributeIDStrstream ; 00150 attributeIDStrstream << attributeID ; 00151 std::string attributeIDStr = attributeIDStrstream.str() ; 00152 00153 unsigned int index = 0 ; 00154 for ( ; index < glacierAttribute.size() ; index++ ) { 00155 if ( attributeIDStr == glacierAttribute[index].id ) { 00156 return index ; 00157 } 00158 } 00159 return 0 ; 00160 } 00161 00162 int GLIMSGlobals::getNdxOfID (const std::vector<Attr> glacierAttribute, const std::string attributeID) { 00163 unsigned int index = 0 ; 00164 for ( ; index < glacierAttribute.size() ; index++ ) { 00165 if ( attributeID == glacierAttribute[index].id ) { 00166 return index ; 00167 } 00168 } 00169 return 0 ; 00170 } 00171 00172
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |