00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef Impala_Application_IDash_ScreenQuery_h
00013 #define Impala_Application_IDash_ScreenQuery_h
00014
00015 #include "ScreenBase.h"
00016
00017 #include "OglGui/Tabs.h"
00018 #include "OglGui/CheckBox.h"
00019 #include "OglGui/CheckBoxListener.h"
00020 #include "OglGui/Button.h"
00021 #include "OglGui/Strut.h"
00022 #include "OglGui/GroupBox.h"
00023 #include "OglGui/Strut.h"
00024 #include "OglGui/ButtonListener.h"
00025 #include "OglGui/RadioGroup.h"
00026 #include "OglGui/OglLib.cpp"
00027
00028 #include "ScreenBrowser.h"
00029
00030 #include "Visualization/GUI/ConceptTreeBrowser.h"
00031
00032 namespace Impala {
00033 namespace Application {
00034 namespace IDash {
00035
00036
00037
00038 class ScreenQuery : public ScreenBase,
00039 public Visualization::GUI::PreviewBarSelectionListener
00040 {
00041
00042 public:
00043
00044 ScreenQuery(int width, int height, ScreenBrowser *browser) :
00045 ScreenBase(width, height)
00046 {
00047 InitScreen(browser);
00048 }
00049
00050 ScreenQuery(OglGui::Window *parent, int width, int height, ScreenBrowser *browser) :
00051 ScreenBase(parent, width, height)
00052 {
00053 InitScreen(browser);
00054 }
00055
00056 ScreenQuery(OglGui::Window *parent, ScreenBrowser *browser) :
00057 ScreenBase(parent)
00058 {
00059 InitScreen(browser);
00060 }
00061
00062
00063
00064
00065 virtual void
00066 PreviewBarSelectionEvent(OglGui::Window *src, std::string concept, bool selected, void* userData)
00067 {
00068 if (userData == (void*) SEL_FROMTREE) {
00069 if (selected) {
00070 ILOG_USER( "selected concept from tree: " << concept );
00071 AddConceptToQuery(concept);
00072 } else {
00073 ILOG_USER( "deselected concept from tree: " << concept );
00074 RemoveConceptFromQuery(concept);
00075 }
00076 }
00077 if (userData == (void*) SEL_FROMSET) {
00078 if (selected) {
00079 ILOG_USER( concept << " selected in suggested set." );
00080 AddComponent("CONCEPT:" + concept);
00081 } else {
00082 ILOG_USER( concept << " deselected in suggested set." );
00083 RemoveComponent("CONCEPT:" + concept);
00084 }
00085 }
00086 }
00087
00088 virtual void
00089 PreviewBarImageClickEvent(OglGui::Window *src, std::string concept, int keyframeID, void* userData)
00090 {
00091
00092 }
00093
00094 virtual void
00095 ButtonSelectionEvent(Button *src, void* vData)
00096 {
00097 int userData = (int)(long long) vData;
00098 switch (userData) {
00099 case BTN_ALLMOVIES:
00100 ILOG_USER("BTN: show all movies");
00101 mBrowser->DoInitialQuery();
00102 break;
00103 case BTN_QUERY:
00104 ILOG_USER("BTN: do query");
00105 mBrowser->DoConceptQuery(mQueryComponents);
00106 break;
00107
00108 case BTN_CLEAR:
00109 ILOG_USER("BTN: do clear");
00110 DoClearSelection();
00111 break;
00112 }
00113 }
00114
00115 private:
00116
00117 void
00118 InitScreen(ScreenBrowser *browser)
00119 {
00120 ILOG_DEBUG("constructing screen Query");
00121
00122 mBrowser = browser;
00123
00124
00125 GroupBox *mCBGroupWnd = new GroupBox(this, 0, 300, W() - 16, H() - 308, "Available semantic concepts");
00126 SetAsBox(mCBGroupWnd);
00127
00128 mConceptTreeBrowserWnd = new Visualization::GUI::ConceptTreeBrowser(mCBGroupWnd,
00129 W(), mCBGroupWnd->H(), Engine()->ImWidth(), Engine()->ImHeight(),
00130 Engine()->ImScale(), Engine()->ThreadSet());
00131 mConceptTreeBrowserWnd->SetPreviewBarSelectionListener(this, (void*)SEL_FROMTREE);
00132
00133
00134 AddConcepts(Engine()->GetConceptRanking());
00135
00136
00137
00138 GroupBox *mSelectedGroupWnd = new GroupBox(this, 0, 0, W() - 16, 292, "Selected semantic concepts");
00139 SetAsBox(mSelectedGroupWnd);
00140 ScrollWnd* suggestionScroller = new ScrollWnd(mSelectedGroupWnd, 0, 0,
00141 mSelectedGroupWnd->W(),
00142 mSelectedGroupWnd->H() - 16, true, 0, -1);
00143 suggestionScroller->ConnectTo(mSelectedGroupWnd, ALLSIDES);
00144 mSuggestionWnd = suggestionScroller->ContentPane();
00145
00146 mSuggestionWnd->SetDimensions(0, 0, suggestionScroller->W(), 1000);
00147 mSuggestionWnd->ConnectTo(suggestionScroller, TPARENT | L2L|R2R);
00148
00149
00150
00151 mBtnSearch = new Button(mSelectedGroupWnd, mSelectedGroupWnd->W() - 180,
00152 8, 160, 28, "Search!");
00153 mBtnSearch->ConnectTo(mSelectedGroupWnd, L2R|R2R|T2T|B2B);
00154 mBtnSearch->SetButtonListener(this, BTN_QUERY);
00155 mBtnSearch->SetRoundness(0,0,0,0);
00156
00157 mBtnAllMovies = new Button(mSelectedGroupWnd, mSelectedGroupWnd->W() - 180 - 140,
00158 8, 120, 28, "Show all videos");
00159 mBtnAllMovies->ConnectTo(mSelectedGroupWnd, L2R|R2R|T2T|B2B);
00160 mBtnAllMovies->SetButtonListener(this, BTN_ALLMOVIES);
00161 mBtnAllMovies->SetRoundness(0,0,0,0);
00162
00163 mBtnClearSelection = new Button(mSelectedGroupWnd, mSelectedGroupWnd->W() - 180 - 140 - 140,
00164 8, 120, 28, "Clear");
00165 mBtnClearSelection->ConnectTo(mSelectedGroupWnd, L2R|R2R|T2T|B2B);
00166 mBtnClearSelection->SetButtonListener(this, BTN_CLEAR);
00167 mBtnClearSelection->SetRoundness(0,0,0,0);
00168
00169
00170
00171
00172
00173 }
00174
00175 void
00176 AddConcepts(Core::Table::SimilarityTableSet* conceptRanking)
00177 {
00178 if (!conceptRanking)
00179 return;
00180
00181 for (int i=0 ; i<conceptRanking->NrTables() ; i++)
00182 {
00183
00184 mConceptTreeBrowserWnd->AddConcept(conceptRanking->GetName(i),
00185 "root", 0.0, 0);
00186 }
00187 }
00188
00189
00190 void
00191 AddConceptToQuery(std::string name, bool selected=true)
00192 {
00193 if (!GetConceptBar(name)) {
00194 int type = 0;
00195
00196 Visualization::GUI::ConceptPreviewBar *nconcept =
00197 new Visualization::GUI::ConceptPreviewBar(mSuggestionWnd,
00198 mSuggestionWnd->W()/3.1, 60, name, Engine()->ThreadSet(), 0.0, selected,
00199 Engine()->ImWidth(), Engine()->ImHeight(), Engine()->ImScale());
00200 nconcept->SetPreviewBarSelectionListener(this, (void*)SEL_FROMSET);
00201 nconcept->SetType(0);
00202 mConceptBars[name] = nconcept;
00203
00204 AddComponent("CONCEPT:" + name);
00205
00206 mSuggestionWnd->RepositionViewports();
00207 mSuggestionWnd->ScaleChildren();
00208
00209 }
00210 }
00211
00212 void
00213 RemoveConceptFromQuery(std::string name)
00214 {
00215 ILOG_DEBUG( "RemoveConceptFromQuery: " << name );
00216 Visualization::GUI::ConceptPreviewBar *b = GetConceptBar(name);
00217 if (b) {
00218 delete b;
00219 mConceptBars.erase(name);
00220
00221 RemoveComponent("CONCEPT:" + name);
00222
00223 mSuggestionWnd->RepositionViewports();
00224 mSuggestionWnd->ScaleChildren();
00225 }
00226 }
00227
00228 void
00229 AddComponent(std::string qomponent)
00230 {
00231 std::list<std::string>::iterator i =
00232 std::find(mQueryComponents.begin(), mQueryComponents.end(), qomponent);
00233 if (i == mQueryComponents.end()) {
00234 ILOG_DEBUG("Query - adding: " << qomponent);
00235 mQueryComponents.push_back(qomponent);
00236 }
00237 }
00238
00239 void
00240 RemoveComponent(std::string qomponent)
00241 {
00242 std::list<std::string>::iterator i =
00243 std::find(mQueryComponents.begin(), mQueryComponents.end(), qomponent);
00244 if (i != mQueryComponents.end()) {
00245 ILOG_DEBUG("Query - removing: " << qomponent);
00246 mQueryComponents.erase(i);
00247 }
00248 }
00249
00250 Visualization::GUI::ConceptPreviewBar*
00251 GetConceptBar(std::string name)
00252 {
00253 if (mConceptBars.find(name) != mConceptBars.end())
00254 return mConceptBars[name];
00255 return NULL;
00256 }
00257
00258 void
00259 DoClearSelection()
00260 {
00261 ILOG_DEBUG( "DoClearSelection()" );
00262
00263 std::map<std::string, Visualization::GUI::ConceptPreviewBar*>::iterator cb;
00264 for (cb = mConceptBars.begin(); cb != mConceptBars.end(); cb++)
00265 delete cb->second;
00266 mConceptBars.clear();
00267
00268 mQueryComponents.clear();
00269 }
00270
00271 public:
00272 const static int SEL_FROMTREE = 1;
00273 const static int SEL_FROMSET = 2;
00274 const static int SEL_SHOTSSET = 3;
00275
00276 const static int BTN_QUERY = 1;
00277 const static int BTN_ALLMOVIES = 2;
00278 const static int BTN_CLEAR = 3;
00279 private:
00280
00281 Visualization::GUI::ConceptTreeBrowser *mConceptTreeBrowserWnd;
00282 std::map<std::string, Visualization::GUI::ConceptPreviewBar*> mConceptBars;
00283 OglGui::Window *mSuggestionWnd;
00284 std::list<std::string> mQueryComponents;
00285
00286 OglGui::Button *mBtnSearch, *mBtnAllMovies, *mBtnClearSelection;
00287
00288 ScreenBrowser *mBrowser;
00289
00290
00291 ILOG_VAR_DEC;
00292 };
00293
00294 ILOG_VAR_INIT(ScreenQuery, Application.IDash);
00295
00296 }
00297 }
00298 }
00299
00300 #endif