00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <globalsearch/tracker.h>
00017 #include <globalsearch/structure.h>
00018
00019 #include <QtCore/QList>
00020 #include <QtCore/QDebug>
00021 #include <QtCore/QReadWriteLock>
00022
00023 using namespace Avogadro;
00024 using namespace OpenBabel;
00025 using namespace Eigen;
00026 using namespace std;
00027
00028 namespace GlobalSearch {
00029
00030 Tracker::Tracker(QObject *parent) :
00031 QObject(parent)
00032 {
00033 }
00034
00035 Tracker::~Tracker()
00036 {
00037 lockForWrite();
00038 }
00039
00040 bool Tracker::append(QList<Structure*> s) {
00041 bool ret = true;
00042 for (int i = 0; i < s.size(); i++) {
00043 if (!append(s.at(i)))
00044 ret = false;
00045 }
00046 return ret;
00047 }
00048
00049 bool Tracker::append(Structure* s) {
00050 if (m_list.contains(s)) {
00051 return false;
00052 }
00053 m_list.append(s);
00054 emit newStructureAdded(s);
00055 emit structureCountChanged(m_list.size());
00056 return true;
00057 }
00058
00059 bool Tracker::popFirst(Structure *&s) {
00060 if (m_list.isEmpty()) {
00061 return false;
00062 }
00063 s = m_list.takeFirst();
00064 emit structureCountChanged(m_list.size());
00065 return true;
00066 }
00067
00068 bool Tracker::remove(Structure *s) {
00069 if (m_list.removeAll(s)) {
00070 emit structureCountChanged(m_list.size());
00071 return true;
00072 }
00073 return false;
00074 }
00075
00076 bool Tracker::contains(Structure* s) {
00077 bool b = m_list.contains(s);
00078 return b;
00079 }
00080
00081 int Tracker::size() {
00082 return m_list.size();
00083 }
00084
00085 void Tracker::reset() {
00086 m_list.clear();
00087 emit structureCountChanged(m_list.size());
00088 }
00089
00090 void Tracker::deleteAllStructures() {
00091 Structure *s = 0;
00092 for (int i = 0; i < m_list.size(); i++) {
00093 s = m_list.at(i);
00094 s->lock()->lockForWrite();
00095 s->deleteLater();
00096 }
00097 m_list.clear();
00098 emit structureCountChanged(m_list.size());
00099 }
00100
00101 }