]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUICommand.cxx
6d99b36c225b9e0ee968a71292c1b030a0d58caa
[bbtk.git] / kernel / src / bbtkWxGUICommand.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUICommand.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:15 $
6   Version:   $Revision: 1.8 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  * \brief Short description in one line
33  * 
34  * Long description which 
35  * can span multiple lines
36  */
37 /**
38  * \file 
39  * \brief 
40  */
41 /**
42  * \class bbtk::
43  * \brief 
44  */
45
46
47 #ifdef _USE_WXWIDGETS_
48
49 #include "bbtkWxGUICommand.h"
50 #include "bbtkMessageManager.h"
51 #include "bbtkConfigurationFile.h"
52 #include "bbtkWxGUIPackageBrowser2.h" 
53
54 namespace bbtk
55 {
56   //================================================================  
57   BEGIN_EVENT_TABLE(WxGUICommand, wxPanel)
58     EVT_TEXT_ENTER(WxGUICommand::ID_Text_Command, WxGUICommand::OnCommandEnter)
59     EVT_BUTTON(WxGUICommand::ID_Btn_Go, WxGUICommand::OnBtnGo)
60     EVT_BUTTON(WxGUICommand::ID_Btn_Include, WxGUICommand::OnBtnInclude)
61     EVT_BUTTON(WxGUICommand::ID_Btn_Reset, WxGUICommand::OnBtnReset)
62     EVT_BUTTON(WxGUICommand::ID_Btn_Config, WxGUICommand::OnBtnConfig)
63     EVT_BUTTON(WxGUICommand::ID_Btn_GraphS, WxGUICommand::OnBtnGraphS)
64     EVT_BUTTON(WxGUICommand::ID_Btn_GraphD, WxGUICommand::OnBtnGraphD)
65     EVT_BUTTON(WxGUICommand::ID_Btn_Help, WxGUICommand::OnBtnHelp)
66     EVT_BUTTON(WxGUICommand::ID_Btn_PackageBrowser, WxGUICommand::OnBtnPackageBrowser)
67    END_EVENT_TABLE()
68   //================================================================
69
70
71   WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
72     : wxPanel(parent,-1),
73       mUser(user)
74   {
75     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
76     
77     mwxTextCommand = 
78       new wxComboBox(this,
79                      ID_Text_Command,
80                      _T(""),
81                      wxDefaultPosition,
82                      wxDefaultSize,
83                      0, NULL,
84                      wxTE_PROCESS_ENTER
85                      //             | wxTE_PROCESS_TAB 
86                      //             | wxWANTS_CHARS 
87                      //             //|  wxTAB_TRAVERSAL
88                      );
89     
90     wxButton *btnGo     = new wxButton(this,ID_Btn_Go,_T("Go"));          
91     
92     wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
93     sizerCommand->AddGrowableCol(0);
94     sizerCommand->Add(mwxTextCommand,1,wxGROW);
95     sizerCommand->Add(btnGo);
96     
97     sizer->Add(sizerCommand,0,wxGROW);
98
99     wxBoxSizer *btnsSizer       = new wxBoxSizer(wxHORIZONTAL);
100     
101     wxButton *btnInclude                = new wxButton(this,ID_Btn_Include              ,_T("include")                  );
102     wxButton *btnReset                  = new wxButton(this,ID_Btn_Reset                ,_T("reset")                    );
103     wxButton *btnConfig                 = new wxButton(this,ID_Btn_Config               ,_T("config")                   );
104     wxButton *btnGraphS                 = new wxButton(this,ID_Btn_GraphS               ,_T("graph (simple)")   );
105     wxButton *btnGraphD                 = new wxButton(this,ID_Btn_GraphD               ,_T("graph (detailed)") );
106     wxButton *btnHelp                   = new wxButton(this,ID_Btn_Help                 ,_T("help")                             );
107     wxButton *btnPackageBrowser    = new wxButton(this,ID_Btn_PackageBrowser    ,_T("Start Package Browser")     );
108     
109     btnsSizer->Add( btnInclude          );
110     btnsSizer->Add( btnReset            );
111     btnsSizer->Add( btnConfig           );
112     btnsSizer->Add( btnGraphS           );
113     btnsSizer->Add( btnGraphD           );
114     btnsSizer->Add( btnHelp             );
115     btnsSizer->Add( btnPackageBrowser   );
116     
117     sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
118
119     SetSizer(sizer);
120     
121     SetAutoLayout(true);
122     Layout();
123   }
124
125   WxGUICommand::~WxGUICommand()
126   {
127   }
128     
129   void WxGUICommand::OnBtnGo(wxCommandEvent& event)
130   {
131     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
132     SendCommand(wx2std(mwxTextCommand->GetValue()));
133   }
134   
135   void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
136   {
137     bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
138     SendCommand(wx2std(mwxTextCommand->GetValue()));
139   }
140   
141   void WxGUICommand::SendCommand(const std::string& command)
142   {
143     if (command.length()==0) return;
144
145     mwxTextCommand->SetValue(_T(""));
146     mwxTextCommand->Append(std2wx(command));
147     if (mUser) mUser->WxGUICommandEnter(command);
148   }
149
150
151   void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
152   {
153     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
154
155     std::string default_doc_dir = 
156       ConfigurationFile::GetInstance().Get_default_temp_dir();
157     std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
158     wxString defaultDir(stdDir.c_str(), wxConvUTF8);
159
160     wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
161     if (dialog.ShowModal() == wxID_OK)
162      {
163        // std::string command(_T("include "));
164        // std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
165        std::string command("include ");
166        command = command + "\"" + wx2std(dialog.GetPath()) + "\"";
167        SendCommand(command);
168      }
169   }
170
171   void WxGUICommand::OnBtnReset(wxCommandEvent& event)
172   {
173     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
174     SendCommand("reset");
175   }
176
177   void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
178   {
179     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
180     SendCommand("config");
181   }
182   
183   void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
184   {
185     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
186     SendCommand("graph");
187   }
188   
189   void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
190   {
191     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
192     SendCommand("graph . 1");
193   }
194
195   void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
196   {
197     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
198     SendCommand("help");
199   }
200
201   void WxGUICommand::OnBtnPackageBrowser(wxCommandEvent& event)
202   {
203         wxBusyCursor wait;
204         WxGUIPackageBrowser2Window *helpbrowser = new
205         WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
206         helpbrowser->Show();
207   }
208   
209 } // namespace bbtk
210
211 #endif //  _USE_WXWIDGETS_