00001 #ifndef Impala_Core_ImageSet_IxsDocument_h
00002 #define Impala_Core_ImageSet_IxsDocument_h
00003
00004 #include "Core/Database/DataDocument.h"
00005 #include "Core/Table/TableIxs.h"
00006 #include "Core/Table/RemoveRow.h"
00007 #include "Core/ImageSet/ImageSet.h"
00008 #include "Core/Column/Copy.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace ImageSet
00015 {
00016
00017
00018 class IxsDocument : public Database::DataDocument
00019 {
00020 public:
00021 typedef Core::Table::TableIxs TableIxs;
00022 typedef TableIxs BookmarkedType;
00023
00024 IxsDocument(ImageSet* imSet) : Database::DataDocument(imSet)
00025 {
00026 mImSet = imSet;
00027 mBookmarked = new TableIxs();
00028 mBookmarkedIds = new TableIds(0);
00029 }
00030
00031 Core::Array::Array2dVec3UInt8*
00032 CurImage()
00033 {
00034 if (!HasCurFile())
00035 return 0;
00036 return mImSet->GetImage(CurFileId());
00037 }
00038
00039 ImageSet*
00040 GetImageSet()
00041 {
00042 return mImSet;
00043 }
00044
00045
00046
00047 Database::DocLevel
00048 CursorToBookmark(int idx)
00049 {
00050 if (mBookmarked->SetCursor(idx))
00051 return CursorToCurBookmark();
00052 return Database::LEVEL_NONE;
00053 }
00054
00055 Database::DocLevel
00056 CursorNextBookmark()
00057 {
00058 if (mBookmarked->MoveCursor(1))
00059 return CursorToCurBookmark();
00060 return Database::LEVEL_NONE;
00061 }
00062
00063 Database::DocLevel
00064 CursorPrevBookmark()
00065 {
00066 if (mBookmarked->MoveCursor(-1))
00067 return CursorToCurBookmark();
00068 return Database::LEVEL_NONE;
00069 }
00070
00071 Database::DocLevel
00072 CursorToCurBookmark()
00073 {
00074 if (!mBookmarked->HasCursor())
00075 return Database::LEVEL_NONE;
00076 GotoFile(mBookmarked->Get7AtCursor());
00077 SetRect(mBookmarked->Get2AtCursor());
00078 SetConcept(mBookmarked->Get1AtCursor());
00079 return Database::LEVEL_FILE;
00080 }
00081
00082
00083
00084 virtual Core::Array::Array2dVec3UInt8*
00085 VisualAtCursor(bool thumbnail)
00086 {
00087
00088 return CurImage();
00089 }
00090
00091
00092
00093 BookmarkedType*
00094 GetBookmarked()
00095 {
00096 return mBookmarked;
00097 }
00098
00099 TableIds*
00100 GetBookmarkedIds()
00101 {
00102 mBookmarkedIds->ReserveMin(mBookmarked->Size(), false);
00103 Column::Copy(mBookmarkedIds->GetColumn1(), mBookmarked->GetColumn7(),
00104 mBookmarked->Size(), 0, 0);
00105 mBookmarkedIds->SetSize(mBookmarked->Size());
00106 return mBookmarkedIds;
00107 }
00108
00109 virtual bool
00110 HasBookmarks()
00111 {
00112 return mBookmarked->Size() > 0;
00113 }
00114
00115 bool
00116 HasCurBookmark()
00117 {
00118 return mBookmarked->HasCursor();
00119 }
00120
00121 int
00122 CurBookmark()
00123 {
00124 return mBookmarked->GetCursor();
00125 }
00126
00127 std::string
00128 CurBookmarkAnno()
00129 {
00130 if (!HasCurBookmark())
00131 return std::string("");
00132 return mBookmarked->Get1AtCursor();
00133 }
00134
00135 virtual std::string
00136 DescribeBookmark(int idx)
00137 {
00138 int fileId = mBookmarked->Get7(idx);
00139 return mDataSet->GetFile(fileId) + " " + mBookmarked->Get1(idx) + " ("
00140 + mDataSet->GetSectionOfFile(fileId)
00141 + "/" + mDataSet->GetDirOfFile(fileId) + ")";
00142 }
00143
00144 virtual bool
00145 AddCursorToBookmarked()
00146 {
00147 if (! HasCurFile())
00148 return false;
00149 Geometry::Rectangle rect = GetRect();
00150 std::string anno = GetConcept();
00151 int fileId = CurFileId();
00152 for (int i=0 ; i<mBookmarked->Size() ; i++)
00153 {
00154 if ((mBookmarked->Get7(i) == fileId) &&
00155 (mBookmarked->Get1(i) == anno) &&
00156 (mBookmarked->Get2(i) == rect))
00157 {
00158 return false;
00159 }
00160 }
00161 if (mBookmarked->Add(anno, rect, mDataSet->GetFile(fileId),
00162 mDataSet->GetSectionOfFile(fileId),
00163 mDataSet->GetDirOfFile(fileId), "", fileId))
00164 {
00165 return true;
00166 }
00167 return false;
00168 }
00169
00170 virtual bool
00171 RemoveCursorFromBookmarked()
00172 {
00173
00174 if (! HasCurBookmark())
00175 return false;
00176 int cursor = mBookmarked->GetCursor();
00177 Table::RemoveRow(mBookmarked, mBookmarked->GetCursor());
00178 CursorToBookmark(cursor);
00179 return true;
00180 }
00181
00182 virtual void
00183 ClearBookmarked()
00184 {
00185 mBookmarked->SetEmpty();
00186 }
00187
00188 virtual void
00189 LoadBookmarked(std::string fileName)
00190 {
00191 mBookmarkedFileName = fileName;
00192 mBookmarked->ReadIxsFile(fileName);
00193 Database::RawDataSet* dataSet = GetDataSet();
00194 for (int i=0 ; i<mBookmarked->Size() ; i++)
00195 {
00196 int fileId = dataSet->GetFileId(mBookmarked->Get4(i),
00197 mBookmarked->Get5(i),
00198 mBookmarked->Get3(i));
00199 mBookmarked->GetColumn7()->Set(i, fileId);
00200 }
00201 }
00202
00203
00204 virtual void
00205 SaveBookmarked(std::string fileName, std::string conceptName)
00206 {
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 }
00227
00228 std::string
00229 GetBookmarkedFileName()
00230 {
00231 return mBookmarkedFileName;
00232 }
00233
00234 void
00235 LoadConceptsFromBookmarks()
00236 {
00237 for (int i=0 ; i<mBookmarked->Size() ; i++)
00238 AddConcept(mBookmarked->Get1(i));
00239 }
00240
00241
00242
00243 virtual void
00244 Clear()
00245 {
00246 Database::DataDocument::Clear();
00247 mBookmarked->SetEmpty();
00248 }
00249
00250 private:
00251
00252 ImageSet* mImSet;
00253 TableIxs* mBookmarked;
00254 TableIds* mBookmarkedIds;
00255 std::string mBookmarkedFileName;
00256
00257 };
00258
00259 }
00260 }
00261 }
00262
00263 #endif