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