00001
00002
00003
00004
00005
00006
00007
00008 #ifndef TIMELINEMODULE_H_
00009 #define TIMELINEMODULE_H_
00010
00011 #include "OglGui/GroupBox.h"
00012 #include "OglGui/Window.h"
00013
00014 #include "OglGui/DocScroller.h"
00015 #include "OglGui/OglLib.cpp"
00016
00017 #include "UnixTimeLine.h"
00018
00019 #ifdef USE_BOOST_THREADPOOL
00020 #include "boost/date_time/posix_time/posix_time.hpp"
00021 #endif
00022
00023 #include "../OglImageCacheStore.h"
00024
00025 namespace Impala {
00026 namespace Application {
00027 namespace MediaTable {
00028
00029 class TimeLineModule : public VisualizationModule
00030 {
00031 public:
00032 typedef OglGui::DocScroller DocScroller;
00033
00034 TimeLineModule() : VisualizationModule("TimeLine")
00035 {
00036 }
00037
00038 void ButtonSelectionEvent(OglGui::Button *src, void *userData)
00039 {
00040 if(src->GetLabel() == "New " + GetName())
00041 {
00042 StoreConfigWindowValues();
00043 DoHandleNewWindow(GetName(), mConfigWindow);
00044 delete mConfigWindow;
00045 DoReleaseConfigWindow();
00046 }
00047
00048
00049 else
00050 VisualizationModule::ButtonSelectionEvent(src, userData);
00051 }
00052
00053 void ViewSelected() {
00054 VisualizationModule::DrawConfigWindow();
00055 OglGui::GroupBox* grp = new OglGui::GroupBox(mConfigWindow, mConfigWindow->W()-2, 362, "");
00056
00057 int timeType = TableDataSource::TYPE_FLAG_NUMBER;
00058 #ifdef USE_BOOST_THREADPOOL
00059 timeType |= TableDataSource::TYPE_TEXT;
00060 #endif
00061 AddSelectorWithColumnsOfType(grp, "Time", mStringValues["View"],
00062 timeType, true);
00063 AddSelectorWithColumnsOfType(grp, "Y", mStringValues["View"],
00064 TableDataSource::TYPE_FLAG_NUMBER, true);
00065 AddSelectorWithColumnsOfType(grp, "Image", mStringValues["View"],
00066 TableDataSource::TYPE_FLAG_IMAGE, true);
00067 (new OglGui::Button(grp, grp->W()-4, 26, "New "+GetName(), BEV_ETCHED))
00068 ->SetButtonListener(this);
00069
00070 grp->RepositionViewports();
00071 grp->ScaleChildren();
00072 }
00073
00074 void NewWindow(OglGui::Window* window)
00075 {
00076 ILOG_DEBUG("Creating new TimeLineWindow.");
00077 TableDataView* mSource = TableDataStore::GetInstance()->GetTableDataView(mStringValues["View"]);
00078 DocScroller* docScroller = new DocScroller(window, window->W(), window->H(), 1);
00079 UnixTimeLine* wndTimeLine =
00080 new UnixTimeLine(docScroller->ContentHolder(),
00081 0, 0, 1000, 300, 0, 3*3600*1000);
00082 wndTimeLine->MapKeysTo(docScroller->HorizontalScrollBar());
00083 docScroller->SetContentPane(wndTimeLine);
00084 docScroller->SetDoc(wndTimeLine);
00085
00086 wndTimeLine->SetLineStipple((short) oglDot);
00087 wndTimeLine->SetViewLineStipple((short) oglDot);
00088
00089 long min = LONG_MAX;
00090 long max = 0;
00091 long ymax = 0;
00092 for (int i=0; i<mSource->GetFilteredRows(); i++)
00093 {
00094 double y;
00095 if(mSource->GetColumn(mStringValues["Y"])->GetType() == TableDataSource::TYPE_INT)
00096 y = mSource->GetSortedIntData(mStringValues["Y"], i);
00097 else
00098 y = mSource->GetSortedDoubleData(mStringValues["Y"], i);
00099 if(y > ymax) ymax = y;
00100 }
00101 double yfactor = (window->H()-64-25.0)/ymax;
00102 ILOG_INFO("yfactor = " << yfactor);
00103 for (int i=0; i<mSource->GetFilteredRows(); i++)
00104 {
00105 OGLVIEW* view =
00106 viewSys.View2D(wndTimeLine->GetOGLWND(), 0, 0, 30, 64, 64);
00107 viewSys.SetTags(view, FlexViewTags);
00108 viewSys.ClearTags(view, deletableTag|showBgTag);
00109
00110 int col = TableDataViewController::MarkToColor(mSource->GetMark(i));
00111 viewSys.SetColor(view, OGL_BORDER, col);
00112
00113 double x = 0, y = 0;
00114
00115 switch (mSource->GetColumn(mStringValues["Time"])->GetType()) {
00116 case TableDataSource::TYPE_INT:
00117 x = mSource->GetSortedIntData(mStringValues["Time"], i);
00118 break;
00119 case TableDataSource::TYPE_DOUBLE:
00120 x = mSource->GetSortedDoubleData(mStringValues["Time"], i);
00121 break;
00122 #ifdef USE_BOOST_THREADPOOL
00123 case TableDataSource::TYPE_TEXT:
00124 std::string txt = mSource->GetSortedTextData(mStringValues["Time"], i);
00125 try
00126 {
00127 boost::posix_time::ptime t(boost::posix_time::time_from_string(txt));
00128 x = mktime(&boost::posix_time::to_tm( t ));
00129 }
00130 catch (boost::bad_lexical_cast)
00131 {
00132 x = 0;
00133 }
00134
00135 break;
00136 #endif
00137 }
00138
00139 if (x < min)
00140 min = x;
00141 if (x > max)
00142 max = x;
00143
00144 if(mSource->GetColumn(mStringValues["Y"])->GetType() == TableDataSource::TYPE_INT)
00145 y = mSource->GetSortedIntData(mStringValues["Y"], i);
00146 else
00147 y = mSource->GetSortedDoubleData(mStringValues["Y"], i);
00148 y *= yfactor;
00149
00150 wndTimeLine->AddImIdOGLVIEW(view, x,
00151 mSource->GetSortedQuid(mStringValues["Image"], i),
00152 0, y);
00153 wndTimeLine->ShowViewAtTickSpanIdx(i, 600000);
00154 wndTimeLine->SetLineColor(view, col);
00155 }
00156 if(max>min)
00157 {
00158 wndTimeLine->DocW(max-min);
00159 wndTimeLine->SetRange(min, max-min);
00160 }
00161 wndTimeLine->ShowNeedle(false);
00162 wndTimeLine->SetGetOglImageByIdInterface(this);
00163 wndTimeLine->SetOglImageCache(OglImageCacheStore::GetInstance());
00164 wndTimeLine->MaxVisibleImages(250);
00165
00166 docScroller->SetBackground(oglGUI_BG);
00167
00168 window->ScaleChildren();
00169 window->SetBackground(oglGUI_BG);
00170 }
00171 protected:
00172 OglGui::OglImageCache* mImCache;
00173
00174 ILOG_VAR_DEC;
00175 };
00176
00177 ILOG_VAR_INIT(TimeLineModule, Application.MediaTable);
00178
00179 } } }
00180
00181 #endif // TIMELINEMODULE_H_