00001 #include "glimsgiddata.h" 00002 #include <iostream> 00003 #include "TraceLog.h" 00004 00005 bool GLIMSGIDData::fromXML( QDomElement &elem ) { 00006 Node *xynode, *llnode; 00007 if ( std::string( "GlacierDefinitionSet" ).compare( (const char*)elem.tagName() ) ) 00008 return false; 00009 00010 QDomNodeList nodelist = 00011 elem.elementsByTagName( "GlacierIDDef" ); 00012 QDomElement e; 00013 for ( unsigned int inode=0; inode < nodelist.count(); inode++ ) { 00014 xynode = new Node; 00015 llnode = new Node; 00016 e = nodelist.item( inode ).toElement(); 00017 GlacierIDDef gid; 00018 gid.fromXML( e ); 00019 mDefSet.push_back( gid ); 00020 llnode->x = gid.mLon; 00021 llnode->y = gid.mLat; 00022 *xynode = *llnode; 00023 mXYSet.push_back( xynode ); 00024 mLLSet.push_back( llnode ); 00025 } 00026 00027 transformDataset(); 00028 emit datasetChanged(); 00029 return true; 00030 } 00031 00032 bool GLIMSGIDData::toXML( QDomDocument &doc, 00033 QDomElement &elem, 00034 std::string id ) { 00035 QDomElement base = doc.createElement( "GlacierDefinitionSet" ); 00036 if ( id != "" ) 00037 base.setAttribute( "id", (char*)id.c_str() ); 00038 elem.appendChild( base ); 00039 00040 for ( unsigned int i=0; i < mDefSet.size(); i++ ) 00041 mDefSet[i].toXML( doc, base ); 00042 00043 return true; 00044 } 00045 00046 void GLIMSGIDData::addNode( Node &node, int ) { 00047 Node *xynode, *llnode; 00048 GlacierIDDef gid; 00049 00050 xynode = new Node; 00051 llnode = new Node; 00052 *xynode = node; 00053 *llnode = node; 00054 // IF THIS DOESN'T HAPPEN -> LAT/LON VALUES WILL REMAIN XY 00055 if ( mImg ) { 00056 mImg->getLL( llnode->x, llnode->y ); 00057 } 00058 00059 gid.mLat = llnode->y; 00060 gid.mLon = llnode->x; 00061 mDefSet.push_back( gid ); 00062 mXYSet.push_back( xynode ); 00063 mLLSet.push_back( llnode ); 00064 00065 clearRedo() ; 00066 emit datasetChanged(); 00067 } 00068 00069 void GLIMSGIDData::delNode( int inode ) { 00070 if ( inode >= 0 && inode < (int)mXYSet.size() ) { 00071 delete mXYSet[inode]; 00072 delete mLLSet[inode]; 00073 00074 mXYSet.erase ( mXYSet.begin() + inode ); 00075 mLLSet.erase ( mLLSet.begin() + inode ); 00076 mDefSet.erase( mDefSet.begin() + inode ); 00077 } 00078 emit datasetChanged(); 00079 } 00080 00081 void GLIMSGIDData::moveNode( Node &node, int inode ) { 00082 if ( inode < 0 || inode >= (int)mXYSet.size() ) return; 00083 Node *xynode, *llnode; 00084 00085 xynode = new Node; 00086 llnode = new Node; 00087 *xynode = node; 00088 *llnode = node; 00089 00090 if ( mImg ) 00091 mImg->getLL( llnode->x, llnode->y ); 00092 GlacierIDDef &def = mDefSet[inode]; 00093 def.mLat = llnode->y; 00094 def.mLon = llnode->x; 00095 mXYSet[inode] = xynode; 00096 mLLSet[inode] = llnode; 00097 00098 clearRedo() ; 00099 emit datasetChanged(); 00100 } 00101 00102 void GLIMSGIDData::insertNode( Node &, int ) { 00103 00104 } 00105 00106 void GLIMSGIDData::push( ) { 00107 std::vector<Shape*> storeLLSet; 00108 std::vector<Shape*> storeXYSet; 00109 00110 for ( int ishp=0; ishp < (int)mLLSet.size(); ishp++ ) { 00111 Shape *lls = mLLSet[ishp]; 00112 Shape *xys = mXYSet[ishp]; 00113 Node *oldxynode = dynamic_cast<Node*>( xys ); 00114 Node *oldllnode = dynamic_cast<Node*>( lls ); 00115 Node *newllnode = new Node; 00116 Node *newxynode = new Node; 00117 *newllnode = *oldllnode; 00118 *newxynode = *oldxynode; 00119 storeLLSet.push_back( newllnode ); 00120 storeXYSet.push_back( newxynode ); 00121 } 00122 00123 00124 mUndoGIDDef.push ( mDefSet ) ; 00125 mUndoLL.push ( storeLLSet ); 00126 mUndoXY.push ( storeXYSet ); 00127 mUndoSel.push( mSelSet ); 00128 } 00129 00130 void GLIMSGIDData::pushRedo( ) { 00131 std::vector<Shape*> storeLLSet; 00132 std::vector<Shape*> storeXYSet; 00133 00134 for ( unsigned int ishp = 0 ; ishp < mLLSet.size(); ishp++ ) { 00135 Shape *lls = mLLSet[ishp]; 00136 Shape *xys = mXYSet[ishp]; 00137 Node *oldxynode = dynamic_cast<Node*>( xys ); 00138 Node *oldllnode = dynamic_cast<Node*>( lls ); 00139 Node *newllnode = new Node; 00140 Node *newxynode = new Node; 00141 *newllnode = *oldllnode; 00142 *newxynode = *oldxynode; 00143 storeLLSet.push_back( newllnode ); 00144 storeXYSet.push_back( newxynode ); 00145 } 00146 00147 mRedoGIDDef.push ( mDefSet ) ; 00148 mRedoLL.push( storeLLSet ); 00149 mRedoXY.push( storeXYSet ); 00150 mRedoSel.push( mSelSet ); 00151 } 00152 00153 void GLIMSGIDData::pop( ) { 00154 00155 // do undo 00156 if ( mUndoLL.size() > 0 ) { 00157 00158 // push current state on redo 00159 pushRedo() ; 00160 // clear current dataset 00161 clear() ; 00162 00163 // set current set to stored set 00164 mLLSet = mUndoLL.top(); 00165 mXYSet = mUndoXY.top(); 00166 mSelSet = mUndoSel.top(); 00167 mDefSet = mUndoGIDDef.top() ; 00168 00169 mUndoLL.pop(); 00170 mUndoXY.pop(); 00171 mUndoSel.pop(); 00172 mUndoGIDDef.pop() ; 00173 } 00174 emit datasetChanged(); 00175 } 00176 00177 void GLIMSGIDData::redo( ) { 00178 00179 // do redo 00180 if ( mRedoLL.size() > 0 ) { 00181 00182 // push info from redo to undo 00183 push() ; 00184 // clear current dataset 00185 clear () ; 00186 00187 // set current set to stored set 00188 mLLSet = mRedoLL.top(); 00189 mXYSet = mRedoXY.top(); 00190 mSelSet = mRedoSel.top(); 00191 mDefSet = mRedoGIDDef.top() ; 00192 00193 mRedoLL.pop(); 00194 mRedoXY.pop(); 00195 mRedoSel.pop(); 00196 mRedoGIDDef.pop() ; 00197 } 00198 emit datasetChanged(); 00199 } 00200 00201 void GLIMSGIDData::clearRedo() { 00202 if (mRedoLL.size() > 0) { 00203 // clear out current set 00204 for ( int ishp=0; ishp < (int)(mRedoLL.top()).size(); ishp++ ) { 00205 00206 Shape *lls = (mRedoLL.top())[ishp]; 00207 Shape *xys = (mRedoXY.top())[ishp]; 00208 Node *oldxynode = dynamic_cast<Node*>( xys ); 00209 Node *oldllnode = dynamic_cast<Node*>( lls ); 00210 delete oldxynode; 00211 delete oldllnode; 00212 00213 } 00214 // mRedoXY.pop() ; 00215 // mRedoLL.pop() ; 00216 // mRedoSel.pop() ; 00217 // mRedoGIDDef.pop() ; 00218 00219 for (unsigned int i = 1 ; i <= mRedoXY.size() ; i++) { 00220 mRedoXY.pop() ; 00221 mRedoLL.pop() ; 00222 mRedoSel.pop() ; 00223 mRedoGIDDef.pop() ; 00224 } 00225 } 00226 } 00227 00228 void GLIMSGIDData::clear() { 00229 if (mLLSet.size() > 0) { 00230 // clear out current set 00231 for ( int ishp=0; ishp < (int)mLLSet.size(); ishp++ ) { 00232 00233 Shape *lls = mLLSet[ishp]; 00234 Shape *xys = mXYSet[ishp]; 00235 Node *oldxynode = dynamic_cast<Node*>( xys ); 00236 Node *oldllnode = dynamic_cast<Node*>( lls ); 00237 delete oldxynode; 00238 delete oldllnode; 00239 00240 } 00241 00242 mXYSet.clear(); 00243 mLLSet.clear(); 00244 mSelSet.clear(); 00245 } 00246 } 00247 00248 00249 void GLIMSGIDData::addGID( const GlacierIDDef &gid ) { 00250 Node *n, *ll; 00251 n = new Node; 00252 ll = new Node; 00253 ll->x = gid.mLon; 00254 ll->y = gid.mLat; 00255 ll->z = 0.0; 00256 *n = *ll; 00257 mImg->getXY( n->x, n->y ); 00258 mXYSet.push_back( n ); 00259 mLLSet.push_back( ll ); 00260 mDefSet.push_back( gid ); 00261 00262 clearRedo() ; 00263 emit datasetChanged(); 00264 } 00265 00266 void GLIMSGIDData::updateVersion (QDate * projectVersion) { 00267 for ( unsigned int i=0; i < mDefSet.size(); i++ ) { 00268 mDefSet[i].updateVersion(projectVersion); 00269 } 00270 emit datasetChanged(); 00271 00272 } 00273 00274
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |