#include <movealgo.h>
Inheritance diagram for MoveAlgo:
Public Member Functions | |
MoveAlgo (TrapperDoc *pDoc_, std::set< db_recno_t > &recnoList, AlgoParam *param) | |
void | start () |
Definition at line 6 of file movealgo.h.
MoveAlgo::MoveAlgo | ( | TrapperDoc * | pDoc_, | |
std::set< db_recno_t > & | recnoList, | |||
AlgoParam * | param | |||
) | [inline] |
void MoveAlgo::start | ( | ) | [virtual] |
Implements Algo.
Definition at line 13 of file movealgo.cpp.
References Database::Creator< T >::create(), Database::Creator< T >::data(), Algo::my_param, Algo::pDoc, ReadData::row(), Algo::selectedReads, ReadData::setEndPos(), GeneralData::setRecno(), ReadData::setRow(), ReadData::setStartPos(), and ReadData::startPos().
00014 { 00015 if ( selectedReads.empty() ) { 00016 return; 00017 } 00018 00019 bool allow_overlap(true); 00020 00021 AlgoMoveParam* param = (AlgoMoveParam*)my_param;//This is so ugly, needs to be fixed!! 00022 assert(param); 00023 00024 int y_delta = param->get_y_delta(); 00025 int x_delta = param->get_x_delta(); 00026 00027 if ( y_delta == 0 && x_delta == 0) { 00028 return; 00029 } 00030 00031 //NB: This should be encapsulated, see TODO list... 00032 00033 //Have to do it in this ugly way since multiple cursors can't be open simultaneously... 00034 00035 vector<ReadData> readvec; 00036 00037 00038 for (set< db_recno_t >::iterator it = selectedReads.begin(); it != selectedReads.end(); it++ ){ 00039 //Have to do it in this ugly way since multiple cursors can't be open simultaneously... FIX THIS!! 00040 //Also, had to move this sucker here (see above) beacause of some NASTY bug with changing read names... 00041 Database::PrimaryIterator<ReadData>* read_it = new Database::PrimaryIterator<ReadData>(pDoc, "ReadData"); 00042 00043 int ret_read = read_it->setFromRecno(*it); 00044 ReadData* r_test = (ret_read != DB_NOTFOUND) ? read_it->answer() : 0; 00045 assert( r_test ); 00046 assert( ret_read == 0 ); 00047 readvec.push_back( *r_test );//Need a copy constructor... 00048 00049 00050 //Check that read does not end up on negative row or negative start index 00051 00052 if ( (static_cast<int>(r_test->row()) + y_delta) < 0 || 00053 (static_cast<int>(r_test->startPos()) + x_delta) < 0 ) { 00054 param->set_y_delta(0); 00055 param->set_x_delta(0); 00056 00057 cerr<<"Read will end up on negative row or col, cancelling move "<<endl; 00058 delete read_it; 00059 return; 00060 } 00061 else { 00062 delete read_it; 00063 } 00064 00065 } 00066 00067 00068 00069 for(size_t i = 0; i < readvec.size(); i++ ) { 00070 00071 00072 //Check so that new destination isn't on another read. Might cause cursor problem, so watch out... 00073 00074 ReadsInRect* dest_it = new ReadsInRect(pDoc); 00075 dest_it->setWindowCoord( readvec[i].startPos() + x_delta, readvec[i].row() + y_delta, readvec[i].endPos() - readvec[i].startPos(), 1); 00076 00077 if ( !allow_overlap && dest_it->first() ) { 00078 //Ooops, read already here... 00079 // cerr<<"Can't move read to occupied space!"<<endl; 00080 delete dest_it; 00081 } 00082 else { 00083 delete dest_it;//This is so ugly... 00084 Database::Creator<ReadData> a_creator(pDoc, "ReadData"); 00085 00086 a_creator.data()->setRecno(readvec[i].getRecno()); 00087 a_creator.data()->setRow(readvec[i].row() + y_delta); 00088 a_creator.data()->setStartPos(readvec[i].startPos() + x_delta); 00089 a_creator.data()->setEndPos(readvec[i].endPos() + x_delta); 00090 // a_creator.data()->setName(readvec[i].name()); 00091 // a_creator.data()->setMate(readvec[i].mate()); 00092 // a_creator.data()->setMateLength(readvec[i].mateLength()); 00093 // a_creator.data()->setStrand(readvec[i].strand()); 00094 // a_creator.data()->setBeginGood(readvec[i].beginGood()); 00095 // a_creator.data()->setEndGood(readvec[i].endGood()); 00096 // a_creator.data()->tc_vec.stlVector() = readvec[i].tc_vec.stlVector(); 00097 00098 00099 00100 a_creator.create(true); 00101 } 00102 00103 } 00104 }