1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUICommand.cxx,v $
5 Date: $Date: 2008/10/17 08:18:15 $
6 Version: $Revision: 1.8 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
32 * \brief Short description in one line
34 * Long description which
35 * can span multiple lines
47 #ifdef _USE_WXWIDGETS_
49 #include "bbtkWxGUICommand.h"
50 #include "bbtkMessageManager.h"
51 #include "bbtkConfigurationFile.h"
52 #include "bbtkWxGUIPackageBrowser2.h"
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)
68 //================================================================
71 WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
75 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
87 // //| wxTAB_TRAVERSAL
90 wxButton *btnGo = new wxButton(this,ID_Btn_Go,_T("Go"));
92 wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
93 sizerCommand->AddGrowableCol(0);
94 sizerCommand->Add(mwxTextCommand,1,wxGROW);
95 sizerCommand->Add(btnGo);
97 sizer->Add(sizerCommand,0,wxGROW);
99 wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL);
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") );
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 );
117 sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
125 WxGUICommand::~WxGUICommand()
129 void WxGUICommand::OnBtnGo(wxCommandEvent& event)
131 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
132 SendCommand(wx2std(mwxTextCommand->GetValue()));
135 void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
137 bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
138 SendCommand(wx2std(mwxTextCommand->GetValue()));
141 void WxGUICommand::SendCommand(const std::string& command)
143 if (command.length()==0) return;
145 mwxTextCommand->SetValue(_T(""));
146 mwxTextCommand->Append(std2wx(command));
147 if (mUser) mUser->WxGUICommandEnter(command);
151 void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
153 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
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);
160 wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
161 if (dialog.ShowModal() == wxID_OK)
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);
171 void WxGUICommand::OnBtnReset(wxCommandEvent& event)
173 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
174 SendCommand("reset");
177 void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
179 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
180 SendCommand("config");
183 void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
185 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
186 SendCommand("graph");
189 void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
191 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
192 SendCommand("graph . 1");
195 void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
197 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
201 void WxGUICommand::OnBtnPackageBrowser(wxCommandEvent& event)
204 WxGUIPackageBrowser2Window *helpbrowser = new
205 WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
211 #endif // _USE_WXWIDGETS_