]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUICommand.cxx
d540113c55689fa60afaa314aca8867852737570
[bbtk.git] / kernel / src / bbtkWxGUICommand.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxGUICommand.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/03/20 15:27:56 $
7   Version:   $Revision: 1.3 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*//**
18  * \brief Short description in one line
19  * 
20  * Long description which 
21  * can span multiple lines
22  */
23 /**
24  * \file 
25  * \brief 
26  */
27 /**
28  * \class bbtk::
29  * \brief 
30  */
31
32
33 #ifdef _USE_WXWIDGETS_
34
35 #include "bbtkWxGUICommand.h"
36 #include "bbtkMessageManager.h"
37 #include "bbtkConfigurationFile.h"
38
39 namespace bbtk
40 {
41   //================================================================  
42   BEGIN_EVENT_TABLE(WxGUICommand, wxPanel)
43     EVT_TEXT_ENTER(WxGUICommand::ID_Text_Command, WxGUICommand::OnCommandEnter)
44     EVT_BUTTON(WxGUICommand::ID_Btn_Go, WxGUICommand::OnBtnGo)
45     EVT_BUTTON(WxGUICommand::ID_Btn_Include, WxGUICommand::OnBtnInclude)
46     EVT_BUTTON(WxGUICommand::ID_Btn_Reset, WxGUICommand::OnBtnReset)
47     EVT_BUTTON(WxGUICommand::ID_Btn_Config, WxGUICommand::OnBtnConfig)
48     EVT_BUTTON(WxGUICommand::ID_Btn_GraphS, WxGUICommand::OnBtnGraphS)
49     EVT_BUTTON(WxGUICommand::ID_Btn_GraphD, WxGUICommand::OnBtnGraphD)
50     EVT_BUTTON(WxGUICommand::ID_Btn_Help, WxGUICommand::OnBtnHelp)
51    END_EVENT_TABLE()
52   //================================================================
53
54
55   WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
56     : wxPanel(parent,-1),
57       mUser(user)
58   {
59     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
60     
61     mwxTextCommand = 
62       new wxComboBox(this,
63                      ID_Text_Command,
64                      _T(""),
65                      wxDefaultPosition,
66                      wxDefaultSize,
67                      0, NULL,
68                      wxTE_PROCESS_ENTER
69                      //             | wxTE_PROCESS_TAB 
70                      //             | wxWANTS_CHARS 
71                      //             //|  wxTAB_TRAVERSAL
72                      );
73     
74     wxButton *btnGo     = new wxButton(this,ID_Btn_Go,_T("Go"));          
75     
76     wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
77     sizerCommand->AddGrowableCol(0);
78     sizerCommand->Add(mwxTextCommand,1,wxGROW);
79     sizerCommand->Add(btnGo);
80     
81     sizer->Add(sizerCommand,0,wxGROW);
82
83     wxBoxSizer *btnsSizer       = new wxBoxSizer(wxHORIZONTAL);
84     
85     wxButton *btnInclude  = new wxButton(this,ID_Btn_Include,_T("include")  );
86     wxButton *btnReset    = new wxButton(this,ID_Btn_Reset,_T("reset")    );
87     wxButton *btnConfig   = new wxButton(this,ID_Btn_Config,_T("config")   );
88     wxButton *btnGraphS   = new wxButton(this,ID_Btn_GraphS,
89                                          _T("graph (simple)") );
90     wxButton *btnGraphD   = new wxButton(this,ID_Btn_GraphD,
91                                          _T("graph (detailed)") );
92     wxButton *btnHelp     = new wxButton(this,ID_Btn_Help,_T("help")     );
93     
94     btnsSizer->Add( btnInclude  );
95     btnsSizer->Add( btnReset            );
96     btnsSizer->Add( btnConfig           );
97     btnsSizer->Add( btnGraphS   );
98     btnsSizer->Add( btnGraphD   );
99     btnsSizer->Add( btnHelp             );
100     
101     sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
102
103     SetSizer(sizer);
104     
105     SetAutoLayout(true);
106     Layout();
107   }
108
109   WxGUICommand::~WxGUICommand()
110   {
111   }
112     
113   void WxGUICommand::OnBtnGo(wxCommandEvent& event)
114   {
115     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
116     SendCommand(wx2std(mwxTextCommand->GetValue()));
117   }
118   
119   void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
120   {
121     bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
122     SendCommand(wx2std(mwxTextCommand->GetValue()));
123   }
124   
125   void WxGUICommand::SendCommand(const std::string& command)
126   {
127     if (command.length()==0) return;
128
129     mwxTextCommand->SetValue(_T(""));
130     mwxTextCommand->Append(std2wx(command));
131     if (mUser) mUser->WxGUICommandEnter(command);
132   }
133
134
135   void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
136   {
137     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
138
139     std::string default_doc_dir = 
140       ConfigurationFile::GetInstance().Get_default_temp_dir();
141     std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
142     wxString defaultDir(stdDir.c_str(), wxConvUTF8);
143
144     wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
145     if (dialog.ShowModal() == wxID_OK)
146      {
147        // std::string command(_T("include "));
148        // std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
149        std::string command("include ");
150        command += wx2std(dialog.GetPath());
151        SendCommand(command);
152      }
153   }
154
155   void WxGUICommand::OnBtnReset(wxCommandEvent& event)
156   {
157     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
158     SendCommand("reset");
159   }
160
161   void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
162   {
163     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
164     SendCommand("config");
165   }
166   
167   void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
168   {
169     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
170     SendCommand("graph");
171   }
172   
173   void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
174   {
175     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
176     SendCommand("graph . 1");
177   }
178
179   void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
180   {
181     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
182     SendCommand("help");
183   }
184   
185 } // namespace bbtk
186
187 #endif //  _USE_WXWIDGETS_