]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUICommand.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUICommand.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxGUICommand.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/06/10 19:19:42 $
7   Version:   $Revision: 1.5 $
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 #include "bbtkWxGUIPackageBrowser2.h" 
39
40 namespace bbtk
41 {
42   //================================================================  
43   BEGIN_EVENT_TABLE(WxGUICommand, wxPanel)
44     EVT_TEXT_ENTER(WxGUICommand::ID_Text_Command, WxGUICommand::OnCommandEnter)
45     EVT_BUTTON(WxGUICommand::ID_Btn_Go, WxGUICommand::OnBtnGo)
46     EVT_BUTTON(WxGUICommand::ID_Btn_Include, WxGUICommand::OnBtnInclude)
47     EVT_BUTTON(WxGUICommand::ID_Btn_Reset, WxGUICommand::OnBtnReset)
48     EVT_BUTTON(WxGUICommand::ID_Btn_Config, WxGUICommand::OnBtnConfig)
49     EVT_BUTTON(WxGUICommand::ID_Btn_GraphS, WxGUICommand::OnBtnGraphS)
50     EVT_BUTTON(WxGUICommand::ID_Btn_GraphD, WxGUICommand::OnBtnGraphD)
51     EVT_BUTTON(WxGUICommand::ID_Btn_Help, WxGUICommand::OnBtnHelp)
52     EVT_BUTTON(WxGUICommand::ID_Btn_HelpBrowser, WxGUICommand::OnBtnHelpBrowser)
53    END_EVENT_TABLE()
54   //================================================================
55
56
57   WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
58     : wxPanel(parent,-1),
59       mUser(user)
60   {
61     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
62     
63     mwxTextCommand = 
64       new wxComboBox(this,
65                      ID_Text_Command,
66                      _T(""),
67                      wxDefaultPosition,
68                      wxDefaultSize,
69                      0, NULL,
70                      wxTE_PROCESS_ENTER
71                      //             | wxTE_PROCESS_TAB 
72                      //             | wxWANTS_CHARS 
73                      //             //|  wxTAB_TRAVERSAL
74                      );
75     
76     wxButton *btnGo     = new wxButton(this,ID_Btn_Go,_T("Go"));          
77     
78     wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
79     sizerCommand->AddGrowableCol(0);
80     sizerCommand->Add(mwxTextCommand,1,wxGROW);
81     sizerCommand->Add(btnGo);
82     
83     sizer->Add(sizerCommand,0,wxGROW);
84
85     wxBoxSizer *btnsSizer       = new wxBoxSizer(wxHORIZONTAL);
86     
87     wxButton *btnInclude                = new wxButton(this,ID_Btn_Include              ,_T("include")                  );
88     wxButton *btnReset                  = new wxButton(this,ID_Btn_Reset                ,_T("reset")                    );
89     wxButton *btnConfig                 = new wxButton(this,ID_Btn_Config               ,_T("config")                   );
90     wxButton *btnGraphS                 = new wxButton(this,ID_Btn_GraphS               ,_T("graph (simple)")   );
91     wxButton *btnGraphD                 = new wxButton(this,ID_Btn_GraphD               ,_T("graph (detailed)") );
92     wxButton *btnHelp                   = new wxButton(this,ID_Btn_Help                 ,_T("help")                             );
93     wxButton *btnHelpBrowser    = new wxButton(this,ID_Btn_HelpBrowser  ,_T("help browser")     );
94     
95     btnsSizer->Add( btnInclude          );
96     btnsSizer->Add( btnReset            );
97     btnsSizer->Add( btnConfig           );
98     btnsSizer->Add( btnGraphS           );
99     btnsSizer->Add( btnGraphD           );
100     btnsSizer->Add( btnHelp             );
101     btnsSizer->Add( btnHelpBrowser      );
102     
103     sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
104
105     SetSizer(sizer);
106     
107     SetAutoLayout(true);
108     Layout();
109   }
110
111   WxGUICommand::~WxGUICommand()
112   {
113   }
114     
115   void WxGUICommand::OnBtnGo(wxCommandEvent& event)
116   {
117     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
118     SendCommand(wx2std(mwxTextCommand->GetValue()));
119   }
120   
121   void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
122   {
123     bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
124     SendCommand(wx2std(mwxTextCommand->GetValue()));
125   }
126   
127   void WxGUICommand::SendCommand(const std::string& command)
128   {
129     if (command.length()==0) return;
130
131     mwxTextCommand->SetValue(_T(""));
132     mwxTextCommand->Append(std2wx(command));
133     if (mUser) mUser->WxGUICommandEnter(command);
134   }
135
136
137   void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
138   {
139     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
140
141     std::string default_doc_dir = 
142       ConfigurationFile::GetInstance().Get_default_temp_dir();
143     std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
144     wxString defaultDir(stdDir.c_str(), wxConvUTF8);
145
146     wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
147     if (dialog.ShowModal() == wxID_OK)
148      {
149        // std::string command(_T("include "));
150        // std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
151        std::string command("include ");
152        command = command + "\"" + wx2std(dialog.GetPath()) + "\"";
153        SendCommand(command);
154      }
155   }
156
157   void WxGUICommand::OnBtnReset(wxCommandEvent& event)
158   {
159     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
160     SendCommand("reset");
161   }
162
163   void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
164   {
165     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
166     SendCommand("config");
167   }
168   
169   void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
170   {
171     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
172     SendCommand("graph");
173   }
174   
175   void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
176   {
177     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
178     SendCommand("graph . 1");
179   }
180
181   void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
182   {
183     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
184     SendCommand("help");
185   }
186
187   void WxGUICommand::OnBtnHelpBrowser(wxCommandEvent& event)
188   {
189         wxBusyCursor wait;
190         WxGUIPackageBrowser2Window *helpbrowser = new WxGUIPackageBrowser2Window(this,"HelpBrowser", wxSize(600,600) );
191         helpbrowser->Show();
192   }
193   
194 } // namespace bbtk
195
196 #endif //  _USE_WXWIDGETS_