Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GuiWX.cpp
1 //include first, avoid macro collision
2 #include <Gui/StringConv.hh>
3 
4 #include "GuiWX.hh"
5 
6 using namespace BIAS;
7 using namespace std;
8 
9 //////////////////////////////////////////////////////////////////////////////
11 {
12  pthread_mutex_init(&guiMutex_,NULL);
13  if(pthread_create(&guiThread_, NULL,
14  (void* (*)(void*))(GuiWX::guiThreadFunc_),this)) {
15  BIASERR("Could not create gui thread");
16  }
17 #ifndef WIN32
18  sleep(1);
19 #else
20  Sleep(1000);
21 #endif
22 }
23 
25  pthread_cancel(guiThread_);
26  wxTheApp->OnExit();
27  wxEntryCleanup();
28 }
29 
30 void* GuiWX::
32  int oldstate=0;
33  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&oldstate);
34 
35  caller->app_ = new GuiWXApp();
36  wxApp::SetInstance(caller->app_);
37  int i=0; wxChar **c=NULL;
38  wxEntryStart(i,c);
39  caller->app_->Init();
40  wxTheApp->OnInit();
41  wxTheApp->OnRun();
42  return NULL;
43 }
44 
45 void GuiWX::
46 SetTitle(std::string const& Title){
47  pthread_mutex_lock(&guiMutex_);
48  app_->SetTitle(Title);
49  pthread_mutex_unlock(&guiMutex_);
50 }
51 
52 int GuiWX::
54  //cout<<"GuiWX::Show Converted image:"<<endl;
55  pthread_mutex_lock(&guiMutex_);
56  app_->ShowConvertedImage(image);
57  pthread_mutex_unlock(&guiMutex_);
58  return 0;
59 }
60 
61 //////////////////////////////////////////////////////////////////////////////
63  frame_ = NULL;
64 }
65 
67  //cout<<"OnInit:"<<endl;
68  frame_ = new GuiWXFrame(wxT("Image"));
69  SetTopWindow(frame_);
70  frame_->Show();
71 }
72 
73 void GuiWXApp::
74 SetTitle(std::string const& Title){
75  if(frame_!=NULL) frame_->SetTitle(Title);
76 }
77 
78 int GuiWXApp::
80 {
81  //cout<<"GuiWXApp::Show Converted image:"<<endl;
82  if(frame_!=NULL)
83  return frame_->ShowConvertedImage(image);
84  else
85  return -1;
86 }
87 
88 /////////////////////////////////////////////////////////////////////////////////
89 GuiWXFrame::GuiWXFrame(const wxString title,
90  const wxPoint pos, const wxSize size)
91 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
92 {
93 
94  panel_ = new wxPanel(this);
95 
96  panel_->Connect(wxEVT_KEY_DOWN,wxKeyEventHandler(GuiWXFrame::OnKeyDown),NULL,this);
97  panel_->Connect(wxEVT_CHAR,wxKeyEventHandler(GuiWXFrame::OnKeyDown),NULL,this);
98 
99  wxSizer *pSizer = new wxBoxSizer( wxHORIZONTAL );
100 
101  ic_ = new PlainImageCanvas(panel_,NULL,0);
102  ic_->SetSize(1024,768);
103  pSizer->Add(panel_,1, wxEXPAND |wxALL , 5);
104  SetSizer( pSizer );
105 
106  Timer_.SetOwner((wxFrame*)this, ID_TIMER);
107  Timer_.Start(20,true);
108  SetAutoLayout(true);
109  Layout();
110  //cout<<"Created new GuiWXFrame"<<endl;;
111 }
112 
113 void GuiWXFrame::
114 SetTitle(std::string const& Title){
115  wxString t = AsciiToWx(Title);
116  wxTopLevelWindow::SetTitle(t);
117 }
118 
119 int GuiWXFrame::
121 {
122  //cout<<"GuiWXFrame::Show Converted image:"<<endl;
123  image_ = image;
124  ic_->Show(image_);
125  //WindowCreated_ = true;
126  Refresh();
127  return 0;
128 }
129 
130 void GuiWXFrame::
131 OnKeyDown(wxKeyEvent &event){
132  int KeyBuffer_ = event.GetKeyCode();
133  cout<<"Key:"<<KeyBuffer_<<endl;
134  event.Skip();
135 }
136 
137 void GuiWXFrame::
138 OnQuit(wxCommandEvent& WXUNUSED(event))
139 {
140  Timer_.Stop();
141 #ifndef WIN32
142  sleep(1);
143 #else
144  Sleep(1000);
145 #endif
146  Destroy();
147 }
148 
149 void GuiWXFrame::
150 OnTimer(wxTimerEvent& event)
151 {
152  Refresh();
153  Timer_.Start(20, true);
154 }
155 
156 
157 /////////////////////////////////////////////////////////////////////////////////
158 BEGIN_EVENT_TABLE(GuiWXFrame, wxFrame)
159  EVT_TIMER(ID_TIMER, GuiWXFrame::OnTimer)
160 END_EVENT_TABLE()
virtual void OnQuit(wxCommandEvent &event)
class BIASGui_EXPORT GuiWXFrame
Definition: GuiWX.hh:46
virtual void SetTitle(std::string const &Title)
Definition: GuiWX.cpp:46
virtual int ShowConvertedImage_(BIAS::Image< unsigned char > &image)
Does the real update of the image shown in window. Must be overloaded.
Definition: GuiWX.cpp:53
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
wxPanel * panel_
Definition: GuiWX.hh:106
simple wxWindow to display an image.
Definition: GuiWX.hh:49
class BIASGui_EXPORT GuiWXApp
Definition: GuiWX.hh:47
void SetTitle(std::string const &Title)
Definition: GuiWX.cpp:74
BIAS::Image< unsigned char > image_
Definition: GuiWX.hh:110
void Init()
Definition: GuiWX.cpp:66
virtual void SetTitle(std::string const &Title)
Definition: GuiWX.cpp:114
int ShowConvertedImage(BIAS::Image< unsigned char > &image)
Definition: GuiWX.cpp:79
GuiWXApp * app_
Definition: GuiWX.hh:58
wxTimer Timer_
Definition: GuiWX.hh:109
Image canvas that does not show zoom frames and redirects mouse click events to its parent...
virtual int ShowConvertedImage(BIAS::Image< unsigned char > &image)
Definition: GuiWX.cpp:120
virtual void OnKeyDown(wxKeyEvent &event)
Definition: GuiWX.cpp:131
virtual void OnTimer(wxTimerEvent &event)
Definition: GuiWX.cpp:150
static void * guiThreadFunc_(GuiWX *caller)
Definition: GuiWX.cpp:31
virtual void Show(BIAS::Image< unsigned char > &im, std::string name="")
GuiWXFrame(const wxString title=wxT(""), const wxPoint pos=wxDefaultPosition, const wxSize size=wxDefaultSize)
Definition: GuiWX.cpp:89
BIAS::PlainImageCanvas * ic_
Definition: GuiWX.hh:107